package com.base.controller.api;

import java.io.*;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.base.Queue.*;
import com.base.comm.CommUrls;
import com.base.comm.ServiceUrls;
import com.base.controller.utils.SBDUtil;
import com.base.controller.utils.qskUtils;
import com.base.helper.*;
import com.base.po.ip.IpStored;
import com.base.po.param.*;
import com.base.po.voip.*;
import com.base.service.*;
import com.base.utils.*;
//import com.base.utils.Redis.RedisCacheManager;
//import com.base.utils.sbd.SBDUtil;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.base.comm.CommContent;
import com.base.po.acess.AcessToken;
import com.base.po.acess.TokenUtils;

import static java.net.URLEncoder.encode;

@Slf4j
@Controller
@RequestMapping("/call")
public class CallController {
    @Autowired
    private ApiinfoesService apiinfoesService;
    @Autowired
    private SubscribersService subscribersService;
    @Autowired
    private UsersService usersService;
    @Autowired
    private CallNumService callNumService;
    @Autowired
    private CallbackinfoesService callbackinfoesService;
    @Autowired
    private FreeroutesService freeroutesService;
    @Autowired
    private ChangeRecordService changeRecordService;
    @Autowired
    private DialogBoxService dialogBoxService;
    @Autowired
    private AdversimentsService adversimentsService; // 轮播广告Service
    @Autowired
    private IpStoredService ipStoredService;
    @Autowired
    private RedisCacheManager redisCacheManager;
    @Autowired
    private CallbackRedirectTableService callbackRedirectTableService;
    @Autowired
    private LogsService logsService;// log日志
    @Autowired
    private JHHelper jhHelper;
    @Autowired
    private BC_JHHelper bcJhHelper;

    // 获取回拨号码
    @CrossOrigin
    @RequestMapping(value = "/getNum", method = {RequestMethod.POST, RequestMethod.GET})
    public @ResponseBody
    NetState getNum(HttpServletRequest request, String ParentId, String Mobile) {
        NetState netState = new NetState();
        List<Callnums> callnums;
        List<Callnumresult> callnumresult = new ArrayList<Callnumresult>();
        CallnumsExample callnumsExample = new CallnumsExample();
        callnumsExample.getOredCriteria()
                .add(callnumsExample.createCriteria().andAgentidEqualTo("7dd9a07e-9cef-4702-a165-b7033861c1b7"));
        Users agent = null;
        if (ParentId != null) {
            agent = usersService.selectByPrimaryKey(ParentId);
        } else {
            agent = usersService.selectByPrimaryKey("7dd9a07e-9cef-4702-a165-b7033861c1b7");
        }
        if (agent == null) {
            agent = usersService.selectByPrimaryKey("7dd9a07e-9cef-4702-a165-b7033861c1b7");
        }
        callnums = callNumService.selectByExample(callnumsExample);
        for (Callnums callnum : callnums) {
            Callnumresult cr = new Callnumresult();
            cr.setAgentid(callnum.getAgentid());
            cr.setId(callnum.getId());
            cr.setNums(callnum.getNums());
            if (agent.getAgentlogo() != null) {
                cr.Logo = agent.getAgentlogo();
            }
            if (agent.getPrefix() != null) {
                cr.Name = agent.getPrefix();
            }
            callnumresult.add(cr);
        }
        Object defultJson = callnumresult;
        if (ParentId == null || ParentId.equals("")) {
            netState.setErrorCode(NetState.SUCCESS_CONN);
            netState.setData("默认回拨号码");
            netState.setJson(defultJson);
        } else {
            callnumsExample.clear();
            callnumsExample.getOredCriteria().add(callnumsExample.createCriteria().andAgentidEqualTo(ParentId));
            callnums = callNumService.selectByExample(callnumsExample);
            if (callnums != null && callnums.size() > 0) {
                callnumresult.clear();
                agent = usersService.selectByPrimaryKey(ParentId);
                for (Callnums callnum : callnums) {
                    Callnumresult cr = new Callnumresult();
                    cr.setAgentid(callnum.getAgentid());
                    cr.setId(callnum.getId());
                    cr.setNums(callnum.getNums());
                    cr.Logo = agent.getAgentlogo();
                    cr.Name = agent.getPrefix();
                    callnumresult.add(cr);
                }
                netState.setErrorCode(NetState.SUCCESS_CONN);
                netState.setData("代理商自定义回拨号码");
                netState.setJson(callnumresult);
            } else {
                netState.setErrorCode(NetState.SUCCESS_CONN);
                netState.setData("默认回拨号码");
                netState.setJson(defultJson);
            }
        }

        // 对话框文字
        Map<String, Object> boxMap = new HashMap<>();
        if (Mobile != null) {
            List<Subscribers> sub = subscribersService.selectBySub(Mobile, ParentId);
            List<DialogBox> shopDialogBox = dialogBoxService.selectByParentId(sub.get(0).getShopid());
            if (shopDialogBox != null && shopDialogBox.size() > 0) {
                boxMap.put("dialogBox", shopDialogBox.size() > 0 ? shopDialogBox.get(0).getText() : null);
                boxMap.put("isDialogBox", agent.getIsdialogbox());
            } else {
                List<DialogBox> dialogBox = dialogBoxService.selectByParentId(agent.getId());
                boxMap.put("dialogBox", dialogBox.size() > 0 ? dialogBox.get(0).getText() : null);
                boxMap.put("isDialogBox", agent.getIsdialogbox());
            }
            netState.setOtherJson(boxMap);
        } else {
            List<DialogBox> dialogBox = dialogBoxService.selectByParentId(agent.getId());
            boxMap.put("dialogBox", dialogBox.size() > 0 ? dialogBox.get(0).getText() : null);
            boxMap.put("isDialogBox", agent.getIsdialogbox());
            netState.setOtherJson(boxMap);
        }

        Apiinfoes apiinfoes = ApiinfoesHelper.createApiinfoes(request, " 获取回拨号码");
        apiinfoesService.insert(ApiinfoesHelper.setApiinfoes(apiinfoes, Produce.parmsToString(ParentId),
                GsonUtil.createJsonString(netState)));
        return netState;
    }

    // 拨打电话
    @CrossOrigin
    @RequestMapping(value = "/callBack", method = RequestMethod.POST)
    public @ResponseBody
    NetState callBack(HttpServletRequest request, String Calle164, String Caller, String ParentId, String MobileNum,
                      Boolean stReturn, Double Longitude, Double Latitude, String IpAddress, String WxOpenId) throws Exception {

        log.warn("[API][/callBack]Calle164 {},Caller{},ParentId{},MobileNum{},stReturn{},Longitude{},Latitude{},IpAddress{},WxOpenId{}",Calle164,Caller,ParentId,MobileNum,stReturn,Longitude,Latitude,IpAddress,WxOpenId);
        long startTime=System.currentTimeMillis();
        log.warn("[API][/callBack][开始时间={}]Caller={},Calle164={}",startTime,Caller,Calle164);
        NetState netState = new NetState();
        // 获取TOKEN
        String AuthorizationToken = null;
        AcessToken acesstoken = null;
        try {
            AuthorizationToken = request.getHeader("SDB-Authorization");
            if (AuthorizationToken != null && !AuthorizationToken.equals("")) {
                acesstoken = TokenUtils.getAcessToken(AuthorizationToken);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        long endtime1=System.currentTimeMillis();
        log.warn("[API][/callBack][开始时间={}]Caller={},Calle164={},[获取token结束={}]",startTime,Caller,Calle164,endtime1-startTime);
        if (IpAddress == null || IpAddress.equals("")) {
//            IpAddress=IP.getIpAddr(request);
            IpAddress = IpUtils.getIpAddr(request);
            log.warn("拨打电话获取到IP" + IpAddress);
        }
        long endtime2=System.currentTimeMillis();
        log.warn("[API][/callBack][开始时间={}]Caller={},Calle164={},[获取IP结束={}]",startTime,Caller,Calle164,endtime2-endtime1);
        String Mobile = null;
        String AgentID = null;
        if (acesstoken == null) {
            Mobile = MobileNum;
            AgentID = ParentId;
        } else {
            Mobile = acesstoken.getMobile();
            AgentID = acesstoken.getParentid();
        }
        String country = null;
        String province = null;
        String city = null;
        String area = null;

        if (Longitude == null || Latitude == null || Longitude.equals("") || Latitude.equals("")) {
            netState.setData("非法访问");
            netState.setErrorCode(NetState.FEAILED);
            return netState;
        }

//        if(Longitude == null || Latitude == null || IpAddress == null ||
//                Longitude.equals("") || Latitude.equals("")|| IpAddress.equals("")){
//            netState.setData("非法访问");
//            netState.setErrorCode(NetState.FEAILED);
//            return netState;
//        }

        if (Longitude != null && Latitude != null && IpAddress != null) {
            Map<String, Object> map = null;
            try {
                map = BaiduMapHelper.getCity(null, Latitude, Longitude);
                country = map.get("country").toString();
                province = map.get("province").toString();
                city = map.get("city").toString();
                area = map.get("district").toString();
            } catch (Exception e) {
                System.out.println("IP地址查询失败");
            }

            List<IpStored> ipStoreds = ipStoredService.selectByIpAddress(IpAddress);
            IpStored ipStored = new IpStored();
            if (ipStoreds != null && ipStoreds.size() > 0) {
                ipStored = ipStoreds.get(0);
                ipStored.setCountry(country);
                ipStored.setProvince(province);
                ipStored.setCity(city);
                ipStored.setArea(area);
                ipStoredService.updateByPrimaryKeySelective(ipStored);
            } else {
                ipStored.setIpaddress(IpAddress);
                ipStored.setCountry(country);
                ipStored.setProvince(province);
                ipStored.setCity(city);
                ipStored.setArea(area);
                ipStored.setCreatetime(Produce.getNowDate());
                ipStoredService.insertSelective(ipStored);
            }
        }
        long endtime3=System.currentTimeMillis();
        log.warn("[API][/callBack][开始时间={}]Caller={},Calle164={},[ipStored插入结束={}]",startTime,Caller,Calle164,endtime3-endtime2);

        // 校验传入参数
        if (AgentID == null || Calle164 == null || Caller == null || AgentID.equals("") || Calle164.equals("")
                || Caller.equals("")) {
            netState.setErrorCode(NetState.PARAMS_ERROR);
            netState.setData("参数异常");
        } else {
            if (!Mobile.equals(Caller)) {
                netState.setData("请填写签名号码");
                netState.setErrorCode(NetState.SIGN_ERROR);
                return netState;
            }
            String caller = Caller.trim().replace(" ", "");
            String calle164 = Calle164.trim().replace(" ", "").replace("+86", "").replace("-", "");
            if (caller.equals(calle164)) {
                netState.setErrorCode(NetState.PARAMS_ERROR);
                netState.setData("请勿拨打自己号码");
            } else {
                // 根据号码查询当前用户
                SubscribersExample subscribersExample = new SubscribersExample();
                subscribersExample.getOredCriteria().add(subscribersExample.createCriteria()
                        .andMobileEqualTo(Caller).andParentidEqualTo(AgentID).andDatastatusEqualTo(true));
                List<Subscribers> subscribers = subscribersService.selectByExample(subscribersExample);
                if (subscribers != null && subscribers.size() > 0) {
                    UsersExample agentsExample = new UsersExample();
                    agentsExample.getOredCriteria().add(agentsExample.createCriteria()
                            .andIdEqualTo(subscribers.get(0).getParentid()).andDatastatusEqualTo(true));
                    UsersExample shopsExample = new UsersExample();
                    shopsExample.getOredCriteria().add(shopsExample.createCriteria()
                            .andIdEqualTo(subscribers.get(0).getShopid()).andDatastatusEqualTo(true));
                    Users agent = null;
                    List<Users> agents = usersService.selectByExample(agentsExample);
                    Users shop = null;
                    List<Users> shops = usersService.selectByExample(shopsExample);
                    if (agents != null && agents.size() > 0) {
                        agent = agents.get(0);// 获取当前用户的上级代理
                    }
                    if (shops != null && shops.size() > 0) {
                        shop = shops.get(0);// 获取当前用户的商户
                    }
                    long endtime4=System.currentTimeMillis();
                    log.warn("[API][/callBack][开始时间={}]Caller={},Calle164={},[查询用户表和代理商表结束={}]",startTime,Caller,Calle164,endtime4-endtime3);
                    if (!shop.getId().equals("80bb361b1b5347a38e0e47fc43d5ae12")){
                        try{
                            Object object= redisCacheManager.get("stopCall");
                            if (object!=null){
                                return new NetState(NetState.FEAILED,"线路维护中,请稍后再试");
                            }
                        }catch (Exception e){
                            return new NetState(NetState.FEAILED,"线路维护中,请稍后再试");
                        }

                    }
                    String uuid = Produce.getUUID();
                    String results = VosHelper.GetVosAccount("{accounts:['" + agent.getUsername() + "']}");
                    VosModelList v2 = GsonUtil.getObject(results, VosModelList.class);
                    String results1 = VosHelper.GetVosAccount(
                            "{accounts:['" + agent.getAgentprefix() + subscribers.get(0).getMobile() + "']}");
                    long endtime5=System.currentTimeMillis();
                    log.warn("[API][/callBack][开始时间={}]Caller={},Calle164={},[VOS查询数据结束={}]",startTime,Caller,Calle164,endtime5-endtime4);

                    VosModelList v21 = GsonUtil.getObject(results1, VosModelList.class);
                    if (v2 != null && v2.retCode == 0) {
                        InfoCustomers info21 = v21.infoCustomers[0];
                        InfoCustomers info2 = v2.infoCustomers[0];
                        if (info21.getMoney().compareTo(new BigDecimal(0)) > 0) {
                            if (info2.getMoney().compareTo(new BigDecimal(0)) > 0
                                    || info2.getLimitMoney().compareTo(new BigDecimal(0)) > 0 || info2.getMoney()
                                    .compareTo(new BigDecimal(0).subtract(info2.getLimitMoney())) >= 0) {
                                Date endTime = new Date(info21.getValidTime());
                                if (Produce.getNowDate().before(endTime)) {
                                    long endtime6=System.currentTimeMillis();
                                    log.warn("[API][/callBack][开始时间={}]Caller={},Calle164={},[验证信息花费={}]",startTime,Caller,Calle164,endtime6-endtime5);

                                    if (stReturn != null && stReturn == false) {
                                        String cpResoult = CPHelper.getCall(request, caller, calle164);
                                        System.out.println(caller + "cp回调：" + cpResoult);
                                        JSONObject obj = JSONObject.fromObject(cpResoult);
                                        CP c1 = null;
                                        try {
                                            c1 = (CP) JSONObject.toBean(obj, CP.class);
                                            if (c1 != null) {
                                                if (c1.getCode() == 1) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            c1.getData().getOrderid(),
                                                            caller, calle164, Produce.getNowDate(), "提交CP线路",
                                                            agent.getId(), "CP线路提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                    // 如果接口线路出现异常走JH
                                                } else {
                                                    String resoult = CallHelper.getCall(request, caller, calle164);
                                                    Call cl = GsonUtil.getObject(resoult, Call.class);
                                                    if (cl != null) {
                                                        if (cl.getCode() == 1) {
                                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                    cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                                    caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                                    agent.getId(), "提交记录", Produce.getNowDate(),
                                                                    Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                    0, subscribers.get(0).getShopid()
                                                            );
                                                            callbackinfoes.setIpaddress(IpAddress);
                                                            callbackinfoes.setCountry(country);
                                                            callbackinfoes.setProvince(province);
                                                            callbackinfoes.setCity(city);
                                                            callbackinfoesService.insertSelective(callbackinfoes);
                                                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                                            netState.setData("正在接通中...");
                                                        } else {
                                                            callbackinfoesService.insert(uuid, caller, calle164,
                                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid());
                                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                            netState.setData("呼叫失败，运营商处出错");
                                                        }
                                                    }
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                        new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("呼叫失败，运营商处出错");
                                            }
                                            // st接口异常 直接进入ZP
                                        } catch (Exception e) {
                                            String resoult = CallHelper.getCall(request, caller, calle164);
                                            System.out.println(resoult);
                                            Call cl = GsonUtil.getObject(resoult, Call.class);
                                            if (cl != null) {
                                                if (cl.getCode() == 1) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                            caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                            agent.getId(), "提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                } else {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                            new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败，运营商处出错");
                                                }
                                            }
                                        }
                                    } else if (shop.getCalltype() == 1) {// 久话
                                        //如果是南海壹号则用总账号进行控制
//                                        if (shop.getParentid().equals("687f444917634ae9ab3d20e97c24ee8e")){
//                                            agent=usersService.selectByPrimaryKey("687f444917634ae9ab3d20e97c24ee8e");
//                                        }
//                                        String token = "JH " + JHHelper.getRedis();
//                                        String resoult = JHHelper.bh(caller, calle164, token, uuid);
                                        String token = "JH " + jhHelper.getRedisNew();
                                        String resoult = jhHelper.bhNew(caller, calle164, token, uuid);
                                        JH jh = GsonUtil.getObject(resoult, JH.class);
                                        if (jh != null) {
                                            if (jh.getResult() == 0) {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                                // 如果接口线路出现异常或者无可用路由等异常问题
                                            } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                    || jh.getResult() == 114 || jh.getResult() == 115
                                                    || jh.getResult() == 116) {
                                                // TODO 对接VOS接口
                                                String data1 = "";
                                                if (agent.getSxxh() != null || agent.getSxxh()) {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                } else {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                }
                                                String result = VosHelper.VosCallBack(data1);
                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                if (v1.retCode == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中，请注意接听回电...");
                                                } else if (v1.retCode == -2) {
                                                    callbackinfoesService.insert(uuid, caller, calle164,
                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                    netState.setData("余额不足");
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            } else if (jh.getResult() == 501) {
//                                                token = "JH " + JHHelper.getToken();// 服务端获取TOKEN
//                                                resoult = JHHelper.bh(caller, calle164, token, uuid);
                                                token = "JH " + jhHelper.getTokenNew();// 服务端获取TOKEN
                                                resoult = jhHelper.bhNew(caller, calle164, token, uuid);
                                                jh = GsonUtil.getObject(resoult, JH.class);
                                                if (jh.getResult() == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                        || jh.getResult() == 114 || jh.getResult() == 115
                                                        || jh.getResult() == 116) {
                                                    // TODO 对接VOS接口
                                                    String data1 = "";
                                                    if (agent.getSxxh() != null || agent.getSxxh()) {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"callerDisplayNumber\":\""
                                                                + Calle164 + "\",\"calleeE164s\":\""
                                                                + "1547448457"
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    } else {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"calleeE164s\":\""
                                                                + (Integer.parseInt("1547448456") + 1)
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    }
                                                    String result = VosHelper.VosCallBack(data1);
                                                    VosModelList v1 = GsonUtil.getObject(result,
                                                            VosModelList.class);
                                                    if (v1.retCode == 0) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中，请注意接听回电...");
                                                    } else if (v1.retCode == -2) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                        netState.setData("余额不足");
                                                    } else {
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败");
                                                    }
                                                } else {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("通话失败:" + jh.getMsg());
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData(jh.getMsg());
                                            }
                                        } else {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 2) {
                                        // TODO 对接VOS接口
                                        String data1 = "";
                                        if (agent.getSxxh() != null || agent.getSxxh()) {
                                            data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                    + "\",\"callerDisplayNumber\":\"" + Calle164
                                                    + "\",\"calleeE164s\":\""
                                                    + "1547448457" + Calle164
                                                    + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                        } else {
                                            data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                    + "\",\"calleeE164s\":\""
                                                    + (Integer.parseInt("1547448456") + 1) + Calle164
                                                    + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                        }
                                        String result = VosHelper.VosCallBack(data1);
                                        VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                        if (v1.retCode == 0) {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                            netState.setData("正在接通中...");
                                        } else if (v1.retCode == -2) {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                            netState.setData("余额不足");
                                        } else {
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败");
                                        }
                                    } else if (shop.getCalltype() == 3) {
                                        String resoult = CallHelper.getCall(request, caller, calle164);
                                        System.out.println(resoult);
                                        Call cl = GsonUtil.getObject(resoult, Call.class);
                                        if (cl != null) {
                                            if (cl.getCode() == 1) {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                        caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                        agent.getId(), "提交记录", Produce.getNowDate(),
                                                        Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                        0, subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                            } else {
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("受国家政策，通话功能国庆期间暂停服务，节后重新开通，给您带来不便，敬请谅解");
                                            }
//                                            else {
//                                                // TODO 对接VOS接口
//                                                String data1 = "";
//                                                if (agent.getSxxh() != null || agent.getSxxh()) {
//                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
//                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
//                                                            + "\",\"calleeE164s\":\""
//                                                            + "1547448457"
//                                                            + Calle164
//                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
//                                                } else {
//                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
//                                                            + "\",\"calleeE164s\":\""
//                                                            + (Integer.parseInt("1547448456") + 1)
//                                                            + Calle164
//                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
//                                                }
//                                                String result = VosHelper.VosCallBack(data1);
//                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
//                                                if (v1.retCode == 0) {
//                                                    callbackinfoesService.insert(uuid, caller, calle164,
//                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
//                                                            Produce.getNowDate(), Produce.getNowDate(),
//                                                            new BigDecimal(0), new BigDecimal(0), 0,
//                                                            subscribers.get(0).getShopid());
//                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
//                                                    netState.setData("正在接通中，请注意接听回电...");
//                                                } else if (v1.retCode == -2) {
//                                                    callbackinfoesService.insert(uuid, caller, calle164,
//                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
//                                                            Produce.getNowDate(), Produce.getNowDate(),
//                                                            new BigDecimal(0), new BigDecimal(0), 0,
//                                                            subscribers.get(0).getShopid());
//                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
//                                                    netState.setData("余额不足");
//                                                } else {
//                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
//                                                    netState.setData("呼叫失败");
//                                                }
//                                            }
                                        } else {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 4) {
                                        String stResoult = STHelper.getCall(request, caller, calle164);
//                                            ST sl = GsonUtil.getObject(stResoult, ST.class);
                                        System.out.println(caller + "回调：" + stResoult);
                                        JSONObject stObj = JSONObject.fromObject(stResoult);
                                        ST s1 = null;
                                        try {
                                            s1 = (ST) JSONObject.toBean(stObj, ST.class);
                                            if (s1 != null) {
                                                if (s1.getCode() == 1) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            s1.getData().getOrderid(),
                                                            caller, calle164, Produce.getNowDate(), "提交ST线路",
                                                            agent.getId(), "提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                    // 如果接口线路出现异常走CP
                                                } else {
                                                    String cpResoult = CPHelper.getCall(request, caller, calle164);
                                                    System.out.println(caller + "cp回调：" + cpResoult);
                                                    JSONObject cpObj = JSONObject.fromObject(cpResoult);
                                                    CP c1 = null;
                                                    try {
                                                        c1 = (CP) JSONObject.toBean(cpObj, CP.class);
                                                        if (c1 != null) {
                                                            if (c1.getCode() == 1) {
                                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                        c1.getData().getOrderid(),
                                                                        caller, calle164, Produce.getNowDate(), "提交CP线路",
                                                                        agent.getId(), "CP线路提交记录", Produce.getNowDate(),
                                                                        Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                        0, subscribers.get(0).getShopid()
                                                                );
                                                                callbackinfoes.setIpaddress(IpAddress);
                                                                callbackinfoes.setCountry(country);
                                                                callbackinfoes.setProvince(province);
                                                                callbackinfoes.setCity(city);
                                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                                netState.setData("正在接通中...");
                                                                // 如果接口线路出现异常走JH
                                                            } else {
                                                                String resoult = CallHelper.getCall(request, caller, calle164);
                                                                System.out.println(resoult);
                                                                Call cl = GsonUtil.getObject(resoult, Call.class);
                                                                if (cl != null) {
                                                                    if (cl.getCode() == 1) {
                                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                                cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                                                caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                                                agent.getId(), "提交记录", Produce.getNowDate(),
                                                                                Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                                0, subscribers.get(0).getShopid()
                                                                        );
                                                                        callbackinfoes.setIpaddress(IpAddress);
                                                                        callbackinfoes.setCountry(country);
                                                                        callbackinfoes.setProvince(province);
                                                                        callbackinfoes.setCity(city);
                                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                                        netState.setData("正在接通中...");
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    } catch (Exception e) {
                                                        String resoult = CallHelper.getCall(request, caller, calle164);
                                                        System.out.println(resoult);
                                                        Call cl = GsonUtil.getObject(resoult, Call.class);
                                                        if (cl != null) {
                                                            if (cl.getCode() == 1) {
                                                                callbackinfoesService.insert(
                                                                        cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                                        caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                                        agent.getId(), "提交记录", Produce.getNowDate(),
                                                                        Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                        0, subscribers.get(0).getShopid());
                                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                                netState.setData("正在接通中...");
                                                            }
                                                        }
                                                    }
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                        new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("呼叫失败，运营商处出错");
                                            }
                                            // st接口异常 直接进入CP
                                        } catch (Exception e) {
                                            String cpResoult = CPHelper.getCall(request, caller, calle164);
                                            System.out.println(caller + "cp回调：" + cpResoult);
                                            JSONObject cpObj = JSONObject.fromObject(cpResoult);
                                            CP c1 = null;
                                            try {
                                                c1 = (CP) JSONObject.toBean(cpObj, CP.class);
                                                if (c1 != null) {
                                                    if (c1.getCode() == 1) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                c1.getData().getOrderid(),
                                                                caller, calle164, Produce.getNowDate(), "提交CP线路",
                                                                agent.getId(), "CP线路提交记录", Produce.getNowDate(),
                                                                Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                0, subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中...");
                                                        // 如果接口线路出现异常走JH
                                                    } else {
                                                        String resoult = CallHelper.getCall(request, caller, calle164);
                                                        System.out.println(resoult);
                                                        Call cl = GsonUtil.getObject(resoult, Call.class);
                                                        if (cl != null) {
                                                            if (cl.getCode() == 1) {
                                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                        cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                                        caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                                        agent.getId(), "提交记录", Produce.getNowDate(),
                                                                        Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                        0, subscribers.get(0).getShopid()
                                                                );
                                                                callbackinfoes.setIpaddress(IpAddress);
                                                                callbackinfoes.setCountry(country);
                                                                callbackinfoes.setProvince(province);
                                                                callbackinfoes.setCity(city);
                                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                                netState.setData("正在接通中...");
                                                            }
                                                        } else {
                                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                    uuid, caller, calle164,
                                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                            );
                                                            callbackinfoes.setIpaddress(IpAddress);
                                                            callbackinfoes.setCountry(country);
                                                            callbackinfoes.setProvince(province);
                                                            callbackinfoes.setCity(city);
                                                            callbackinfoesService.insertSelective(callbackinfoes);
                                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                            netState.setData("呼叫失败，运营商处出错");
                                                        }
                                                    }
                                                }
                                            } catch (Exception ex) {
                                                String resoult = CallHelper.getCall(request, caller, calle164);
                                                System.out.println(resoult);
                                                Call cl = GsonUtil.getObject(resoult, Call.class);
                                                if (cl != null) {
                                                    if (cl.getCode() == 1) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                                caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                                agent.getId(), "提交记录", Produce.getNowDate(),
                                                                Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                0, subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中...");
                                                    } else {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                                new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败，运营商处出错");
                                                    }
                                                }
                                            }
                                        }
                                    } else if (shop.getCalltype() == 5) {
                                        String cpResoult = CPHelper.getCall(request, caller, calle164);
                                        System.out.println(caller + "cp回调：" + cpResoult);
                                        JSONObject obj = JSONObject.fromObject(cpResoult);
                                        CP c1 = null;
                                        try {
                                            c1 = (CP) JSONObject.toBean(obj, CP.class);
                                            if (c1 != null) {
                                                if (c1.getCode() == 1) {
                                                    callbackinfoesService.insert(
                                                            c1.getData().getOrderid(),
                                                            caller, calle164, Produce.getNowDate(), "提交CP线路",
                                                            agent.getId(), "CP线路提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                    // 如果接口线路出现异常走JH
                                                } else {
                                                    String resoult = CallHelper.getCall(request, caller, calle164);
                                                    System.out.println(resoult);
                                                    Call cl = GsonUtil.getObject(resoult, Call.class);
                                                    if (cl != null) {
                                                        if (cl.getCode() == 1) {
                                                            callbackinfoesService.insert(
                                                                    cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                                    caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                                    agent.getId(), "提交记录", Produce.getNowDate(),
                                                                    Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                    0, subscribers.get(0).getShopid());
                                                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                                            netState.setData("正在接通中...");
                                                        } else {
                                                            callbackinfoesService.insert(uuid, caller, calle164,
                                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid());
                                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                            netState.setData("呼叫失败，运营商处出错");
                                                        }
                                                    }
                                                }
                                            } else {
                                                callbackinfoesService.insert(uuid, caller, calle164,
                                                        Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                        new BigDecimal(0), 0, subscribers.get(0).getShopid());
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("呼叫失败，运营商处出错");
                                            }
                                            // st接口异常 直接进入ZP
                                        } catch (Exception e) {
                                            String resoult = CallHelper.getCall(request, caller, calle164);
                                            System.out.println(resoult);
                                            Call cl = GsonUtil.getObject(resoult, Call.class);
                                            if (cl != null) {
                                                if (cl.getCode() == 1) {
                                                    callbackinfoesService.insert(
                                                            cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                            caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                            agent.getId(), "提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                } else {
                                                    callbackinfoesService.insert(uuid, caller, calle164,
                                                            Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                            new BigDecimal(0), 0, subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败，运营商处出错");
                                                }
                                            }
                                        }
                                    } else if (shop.getCalltype() == 6) {
                                        String cpResoult = XGJCPHelper.getCall(request, caller, calle164);
                                        System.out.println(caller + "cp回调：" + cpResoult);
                                        JSONObject obj = JSONObject.fromObject(cpResoult);
                                        CP c1 = null;
                                        try {
                                            c1 = (CP) JSONObject.toBean(obj, CP.class);
                                            if (c1 != null) {
                                                if (c1.getCode() == 1) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            c1.getData().getOrderid(),
                                                            caller, calle164, Produce.getNowDate(), "提交CP线路",
                                                            agent.getId(), "CP线路提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                        new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("呼叫失败，运营商处出错");
                                            }
                                            // st接口异常 直接进入ZP
                                        } catch (Exception e) {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 7) {// 久话
                                        String token = "JH " + bcJhHelper.getRedis();
                                        String resoult = BC_JHHelper.bh(caller, calle164, token, uuid);
                                        JH jh = GsonUtil.getObject(resoult, JH.class);
                                        if (jh != null) {
                                            if (jh.getResult() == 0) {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                                // 如果接口线路出现异常或者无可用路由等异常问题
                                            } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                    || jh.getResult() == 114 || jh.getResult() == 115
                                                    || jh.getResult() == 116) {
                                                // TODO 对接VOS接口
                                                String data1 = "";
                                                if (agent.getSxxh() != null || agent.getSxxh()) {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                } else {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                }
                                                String result = VosHelper.VosCallBack(data1);
                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                if (v1.retCode == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中，请注意接听回电...");
                                                } else if (v1.retCode == -2) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                    netState.setData("余额不足");
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            } else if (jh.getResult() == 501) {
                                                token = "JH " + bcJhHelper.getToken();// 服务端获取TOKEN
                                                resoult = BC_JHHelper.bh(caller, calle164, token, uuid);
                                                jh = GsonUtil.getObject(resoult, JH.class);
                                                if (jh.getResult() == 0) {
                                                    callbackinfoesService.insert(uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                        || jh.getResult() == 114 || jh.getResult() == 115
                                                        || jh.getResult() == 116) {
                                                    // TODO 对接VOS接口
                                                    String data1 = "";
                                                    if (agent.getSxxh() != null || agent.getSxxh()) {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"callerDisplayNumber\":\""
                                                                + Calle164 + "\",\"calleeE164s\":\""
                                                                + "1547448457"
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    } else {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"calleeE164s\":\""
                                                                + (Integer.parseInt("1547448456") + 1)
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    }
                                                    String result = VosHelper.VosCallBack(data1);
                                                    VosModelList v1 = GsonUtil.getObject(result,
                                                            VosModelList.class);
                                                    if (v1.retCode == 0) {
                                                        callbackinfoesService.insert(uuid, caller, calle164,
                                                                Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid());
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中，请注意接听回电...");
                                                    } else if (v1.retCode == -2) {
                                                        callbackinfoesService.insert(uuid, caller, calle164,
                                                                Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid());
                                                        netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                        netState.setData("余额不足");
                                                    } else {
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败");
                                                    }
                                                } else {
                                                    callbackinfoesService.insert(uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("通话失败:" + jh.getMsg());
                                                }
                                            } else {
                                                callbackinfoesService.insert(uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid());
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData(jh.getMsg());
                                            }
                                        } else {
                                            callbackinfoesService.insert(uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid());
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 8) {
                                        String resoult = XGJCPHelper.getZPCall(request, caller, calle164);
                                        System.out.println(resoult);
                                        Call cl = GsonUtil.getObject(resoult, Call.class);
                                        try {
                                            if (cl != null) {
                                                if (cl.getCode() == 1) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                            caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                            agent.getId(), "提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                        new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("呼叫失败，运营商处出错");
                                            }
                                            // st接口异常 直接进入ZP
                                        } catch (Exception e) {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 9) {
                                        if (Longitude == null || Latitude == null) {
                                            netState.setErrorCode(NetState.UNKNOWN_IP);
                                            netState.setData("请先授权定位，旧版本请立即升级新版");
                                            return netState;
                                        }
//                                        if (WxOpenId == null || WxOpenId.equals("")) {
//                                            if (subscribers.get(0).getWxopenid() == null || subscribers.get(0).getWxopenid().equals("")) {
//                                                netState.setErrorCode(NetState.WX_OPENID_UNBOUND);
//                                                netState.setData("请退出当前登录，使用微信授权登陆绑定您的信息后使用");
//                                                return netState;
//                                            } else {
//                                                WxOpenId = subscribers.get(0).getWxopenid();
//                                            }
//                                        }

                                        String token = "JH " + jhHelper.getRedis();
                                        String resoult = jhHelper.bh(caller, calle164, token, uuid);
//                                        String token = "JH " + JHHelper.getRedisNew();
//                                        String resoult = JHHelper.bhNew(caller, calle164, token, uuid);
                                        JH jh = GsonUtil.getObject(resoult, JH.class);
                                        if (jh != null && jh.getResult() == 501){
                                            token = "JH " + jhHelper.getToken();
                                            resoult = jhHelper.bh(caller, calle164, token, uuid);
                                            jh = GsonUtil.getObject(resoult, JH.class);
                                        }

                                        if (jh != null && jh.getResult() == 0) {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(),
                                                    new BigDecimal(0), new BigDecimal(0), 0,
                                                    subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoes.setWxopenid(WxOpenId);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                            netState.setData("正在接通中...");
                                            // 如果接口线路出现异常或者无可
                                        }else{
                                            String tokenNew = "JH " + jhHelper.getRedisNew();
                                            log.warn("使用new线路");
                                            String resoultNew = jhHelper.bhNew(caller, calle164, tokenNew, uuid);
                                            log.warn("caller={},calle164={},tokenNew={},uuid={},result={}",caller,calle164,tokenNew,uuid,resoultNew);
                                            JH jhNew = GsonUtil.getObject(resoultNew, JH.class);
                                            System.out.println("api异常进去new：" + JSONObject.fromObject(jhNew));
                                            if (jhNew != null) {
                                                if (jhNew.getResult() == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), jhNew.getMsg(), agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                    // 如果接口线路出现异常或者无可用路由等异常问题
                                                } else if (jhNew.getResult() == 501) {
                                                    token = "JH " + jhHelper.getTokenNew();// 服务端获取TOKEN
                                                    resoult = jhHelper.bhNew(caller, calle164, token, uuid);
                                                    jh = GsonUtil.getObject(resoult, JH.class);
                                                    if (jh.getResult() == 0) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                                "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中...");
                                                    }else{
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败");
                                                    }
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            }
                                        }
                                    } else if (shop.getCalltype() == 10) {
                                        IpAddress = IpRandomUtils.getRandomIp();
                                        String token = "JH " + jhHelper.getRedisCustom(shop);
                                        String resoult = jhHelper.bhCustom(shop, caller, calle164, token, uuid, IpAddress);
                                        JH jh = GsonUtil.getObject(resoult, JH.class);
                                        if (jh != null) {
                                            if (jh.getResult() == 0) {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                                // 如果接口线路出现异常或者无可用路由等异常问题
                                            } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                    || jh.getResult() == 114 || jh.getResult() == 115
                                                    || jh.getResult() == 116) {
                                                // TODO 对接VOS接口
                                                String data1 = "";
                                                if (agent.getSxxh() != null || agent.getSxxh()) {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                } else {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                }
                                                String result = VosHelper.VosCallBack(data1);
                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                if (v1.retCode == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中，请注意接听回电...");
                                                } else if (v1.retCode == -2) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                    netState.setData("余额不足");
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            } else if (jh.getResult() == 501) {
                                                token = "JH " + jhHelper.getTokenCustom(shop);// 服务端获取TOKEN
                                                resoult = jhHelper.bhCustom(shop, caller, calle164, token, uuid, IpAddress);
                                                jh = GsonUtil.getObject(resoult, JH.class);
                                                if (jh.getResult() == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                        || jh.getResult() == 114 || jh.getResult() == 115
                                                        || jh.getResult() == 116) {
                                                    // TODO 对接VOS接口
                                                    String data1 = "";
                                                    if (agent.getSxxh() != null || agent.getSxxh()) {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"callerDisplayNumber\":\""
                                                                + Calle164 + "\",\"calleeE164s\":\""
                                                                + "1547448457"
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    } else {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"calleeE164s\":\""
                                                                + (Integer.parseInt("1547448456") + 1)
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    }
                                                    String result = VosHelper.VosCallBack(data1);
                                                    VosModelList v1 = GsonUtil.getObject(result,
                                                            VosModelList.class);
                                                    if (v1.retCode == 0) {
                                                        callbackinfoesService.insert(uuid, caller, calle164,
                                                                Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid());
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中，请注意接听回电...");
                                                    } else if (v1.retCode == -2) {
                                                        callbackinfoesService.insert(uuid, caller, calle164,
                                                                Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid());
                                                        netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                        netState.setData("余额不足");
                                                    } else {
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败");
                                                    }
                                                } else {
                                                    callbackinfoesService.insert(uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("通话失败:" + jh.getMsg());
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData(jh.getMsg());
                                            }
                                        } else {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 11) {
                                        // SC线路通话:
                                        String token = SCHelper.getToken();
                                        String resoult = SCHelper.BeginCall(caller, calle164, token, uuid);
                                        SC sc = GsonUtil.getObject(resoult, SC.class);
                                        if (sc != null) {
                                            if (sc.getResultcode().equals("0")) {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), sc.getResultcode(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                                // 如果接口线路出现异常或者无可用路由等异常问题
                                            } else if (sc.getResultcode().equals("1010001") || sc.getResultcode().equals("1020001")
                                                    || sc.getResultcode().equals("1020002") || sc.getResultcode().equals("1020150")
                                                    || sc.getResultcode().equals("1020154")) {
                                                // TODO 对接VOS接口
                                                String data1 = "";
                                                if (agent.getSxxh() != null || agent.getSxxh()) {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                } else {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                }
                                                String result = VosHelper.VosCallBack(data1);
                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                if (v1.retCode == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中，请注意接听回电...");
                                                } else if (v1.retCode == -2) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                    netState.setData("余额不足");
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), sc.getResultcode(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData(sc.getResultdesc());
                                            }
                                        } else {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 12) {
                                        uuid = ServiceUrls.servicePrefix + uuid;
                                        //云讯科技
                                        JSONObject jsonObject = ZJYCallHelper.httpPhone(caller, calle164, "86164", uuid);
                                        if (jsonObject != null) {
                                            //token 过期时候的处理方式 刷新授权
//                                                if (sc.getResultcode().equals("1010005") || sc.getResultcode().equals("1010004")) {
//                                                }
                                            //如果是线路饱满，则重试5次
                                            int count = 5;
                                            while (jsonObject.getString("statusCode").equals("-104") && count > 0) {
                                                jsonObject = ZJYCallHelper.httpPhone(caller, calle164, "86164", uuid);
                                                count--;
                                            }
                                            if (jsonObject.getString("statusCode").equals("-104") && count <= 0){
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("线路忙,请稍后再试");
                                                return netState;
                                            }

                                            if (jsonObject.getString("statusCode").equals("200")) {
                                                log.warn("呼叫成功");
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jsonObject.getString("statusCode"), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                                // 如果接口线路出现异常或者无可用路由等异常问题
                                            } else {
                                                // TODO 对接VOS接口
                                                String data1 = "";
                                                if (agent.getSxxh() != null || agent.getSxxh()) {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                } else {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                }
                                                String result = VosHelper.VosCallBack(data1);
                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                if (v1.retCode == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中，请注意接听回电...");
                                                } else if (v1.retCode == -2) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                    netState.setData("余额不足");
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            }
                                        } else {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    }else if(shop.getCalltype() == 13){
                                        uuid = ServiceUrls.servicePrefix + uuid;
                                        String result1="";
                                        try{
                                            result1=  SCZHHelper.callPhone(caller,calle164,uuid);
                                            com.alibaba.fastjson.JSONObject jsonObject= com.alibaba.fastjson.JSONObject.parseObject(result1);
                                            if (jsonObject != null) {
                                                if (jsonObject.getString("errno").equals("0")) {
                                                    log.warn("呼叫成功");
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), jsonObject.getString("statusCode"), agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                    // 如果接口线路出现异常或者无可用路由等异常问题
                                                } else {
                                                    // TODO 对接VOS接口
                                                    String data1 = "";
                                                    if (agent.getSxxh() != null || agent.getSxxh()) {
                                                        data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                                + "\",\"callerDisplayNumber\":\"" + Calle164
                                                                + "\",\"calleeE164s\":\""
                                                                + "1547448457"
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    } else {
                                                        data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                                + "\",\"calleeE164s\":\""
                                                                + "1547448457"
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    }
                                                    String result = VosHelper.VosCallBack(data1);
                                                    VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                    if (v1.retCode == 0) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中，请注意接听回电...");
                                                    } else if (v1.retCode == -2) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                        netState.setData("余额不足");
                                                    } else {
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败");
                                                    }
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                        new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("呼叫失败，运营商处出错");
                                            }
                                        }catch (Exception e){
                                            if (Longitude == null || Latitude == null) {
                                                netState.setErrorCode(NetState.UNKNOWN_IP);
                                                netState.setData("请先授权定位，旧版本请立即升级新版");
                                                return netState;
                                            }
                                            if (WxOpenId == null || WxOpenId.equals("")) {
                                                if (subscribers.get(0).getWxopenid() == null || subscribers.get(0).getWxopenid().equals("")) {
                                                    netState.setErrorCode(NetState.WX_OPENID_UNBOUND);
                                                    netState.setData("请退出当前登录，使用微信授权登陆绑定您的信息后使用");
                                                    return netState;
                                                } else {
                                                    WxOpenId = subscribers.get(0).getWxopenid();
                                                }
                                            }

                                            String token = "JH " + jhHelper.getRedisNew();
                                            String resoult = jhHelper.bhNew(caller, calle164, token, uuid);
//                                        String token = "JH " + JHHelper.getRedisNew();
//                                        String resoult = JHHelper.bhNew(caller, calle164, token, uuid);
                                            JH jh = GsonUtil.getObject(resoult, JH.class);
                                            if (jh != null) {
                                                if (jh.getResult() == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoes.setWxopenid(WxOpenId);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                    // 如果接口线路出现异常或者无可用路由等异常问题
                                                } else if (jh.getResult() == 101 || jh.getResult() == 124) {
                                                    String tokenNew = "JH " + jhHelper.getRedisNew();
                                                    String resoultNew = jhHelper.bhNew(caller, calle164, tokenNew, uuid);
                                                    JH jhNew = GsonUtil.getObject(resoultNew, JH.class);
                                                    if (jhNew != null) {
                                                        if (jhNew.getResult() == 0) {
                                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                    uuid, caller, calle164,
                                                                    Produce.getNowDate(), jhNew.getMsg(), agent.getId(), "提交记录",
                                                                    Produce.getNowDate(), Produce.getNowDate(),
                                                                    new BigDecimal(0), new BigDecimal(0), 0,
                                                                    subscribers.get(0).getShopid()
                                                            );
                                                            callbackinfoes.setIpaddress(IpAddress);
                                                            callbackinfoes.setCountry(country);
                                                            callbackinfoes.setProvince(province);
                                                            callbackinfoes.setCity(city);
                                                            callbackinfoesService.insertSelective(callbackinfoes);
                                                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                                            netState.setData("正在接通中...");
                                                            // 如果接口线路出现异常或者无可用路由等异常问题
                                                        } else {
                                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                            netState.setData("呼叫失败");
                                                        }
                                                    }
                                                } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                        || jh.getResult() == 114 || jh.getResult() == 115
                                                        || jh.getResult() == 116) {
                                                    // TODO 对接VOS接口
                                                    String data1 = "";
                                                    if (agent.getSxxh() != null || agent.getSxxh()) {
                                                        data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                                + "\",\"callerDisplayNumber\":\"" + Calle164
                                                                + "\",\"calleeE164s\":\""
                                                                + "1547448457"
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    } else {
                                                        data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                                + "\",\"calleeE164s\":\""
                                                                + "1547448457"
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    }
                                                    String result = VosHelper.VosCallBack(data1);
                                                    VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                    if (v1.retCode == 0) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中，请注意接听回电...");
                                                    } else if (v1.retCode == -2) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                        netState.setData("余额不足");
                                                    } else {
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败");
                                                    }
                                                } else if (jh.getResult() == 501) {
                                                    log.warn("[结果501]");
                                                    token = "JH " + jhHelper.getTokenNew();// 服务端获取TOKEN
                                                    resoult = jhHelper.bhNew(caller, calle164, token, uuid);
//                                                token = "JH " + JHHelper.getTokenNew();// 服务端获取TOKEN
//                                                resoult = JHHelper.bhNew(caller, calle164, token, uuid);
                                                    jh = GsonUtil.getObject(resoult, JH.class);
                                                    if (jh.getResult() == 0) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                                "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中...");
                                                    } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                            || jh.getResult() == 114 || jh.getResult() == 115
                                                            || jh.getResult() == 116) {
                                                        // TODO 对接VOS接口
                                                        String data1 = "";
                                                        if (agent.getSxxh() != null || agent.getSxxh()) {
                                                            data1 = "{\"callerE164\":\"" + "1547448456"
                                                                    + Caller + "\",\"callerDisplayNumber\":\""
                                                                    + Calle164 + "\",\"calleeE164s\":\""
                                                                    + "1547448457"
                                                                    + Calle164
                                                                    + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                        } else {
                                                            data1 = "{\"callerE164\":\"" + "1547448456"
                                                                    + Caller + "\",\"calleeE164s\":\""
                                                                    + (Integer.parseInt("1547448456") + 1)
                                                                    + Calle164
                                                                    + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                        }
                                                        String result = VosHelper.VosCallBack(data1);
                                                        VosModelList v1 = GsonUtil.getObject(result,
                                                                VosModelList.class);
                                                        if (v1.retCode == 0) {
                                                            callbackinfoesService.insert(uuid, caller, calle164,
                                                                    Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                                    Produce.getNowDate(), Produce.getNowDate(),
                                                                    new BigDecimal(0), new BigDecimal(0), 0,
                                                                    subscribers.get(0).getShopid());
                                                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                                            netState.setData("正在接通中，请注意接听回电...");
                                                        } else if (v1.retCode == -2) {
                                                            callbackinfoesService.insert(uuid, caller, calle164,
                                                                    Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                                    Produce.getNowDate(), Produce.getNowDate(),
                                                                    new BigDecimal(0), new BigDecimal(0), 0,
                                                                    subscribers.get(0).getShopid());
                                                            netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                            netState.setData("余额不足");
                                                        } else {
                                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                            netState.setData("呼叫失败");
                                                        }
                                                    } else {
                                                        callbackinfoesService.insert(uuid, caller, calle164,
                                                                Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                                "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid());
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("通话失败:" + jh.getMsg());
                                                    }
                                                } else {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData(jh.getMsg());
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                        new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("呼叫失败，运营商处出错");
                                            }

                                        }
                                    }else if(shop.getCalltype() == 14){
                                        if(StringUtils.isEmpty(IpAddress)){
                                            IpAddress="192.168.10.33";
                                        }
                                        String result=CallHelper14.doCall(caller,calle164,IpAddress,uuid);
                                        log.warn("14号线路拨号:"+result);
                                        com.alibaba.fastjson.JSONObject res= JSON.parseObject(result);
                                        if(res.getString("code").equals("1")){
                                            log.warn("14号线路拨通成功");
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(),
                                                    new BigDecimal(0), new BigDecimal(0), 0,
                                                    subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                            netState.setData("正在接通中，请注意接听回电...");
                                        }else {
                                            log.warn("拨号失败"+result);
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    }else if(shop.getCalltype() == 15){
                                        if(StringUtils.isEmpty(IpAddress)){
                                            IpAddress="192.168.10.33";
                                        }
                                        String result=CallHelper15.doCall(caller,calle164,IpAddress,uuid);
                                        log.warn("15号线路拨号:"+result);
                                        com.alibaba.fastjson.JSONObject res= JSON.parseObject(result);
                                        if(res.getString("code").equals("1")){
                                            log.warn("15号线路拨通成功");
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(),
                                                    new BigDecimal(0), new BigDecimal(0), 0,
                                                    subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                            netState.setData("正在接通中，请注意接听回电...");
                                        }else {
                                            log.warn("拨号失败"+result);
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    }else {
                                        netState.setErrorCode(NetState.FEAILED);
                                        netState.setData("该用户没有指定的拨号方式");
                                    }
                                } else {
                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                    netState.setData("您的账户已经过期");
                                }
                            } else {
                                netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                netState.setData("线路暂时无法使用");
                            }
                        } else {
                            netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                            netState.setData("余额不足");
                        }
                    }
                    /**** 上述内容需要代理商有话费、用户有话费 ****/
                    /**** 上述内容需要代理商线路以及账户正常 ****/
                } else {
                    netState.setErrorCode(NetState.NODATA);
                    netState.setData("用户不存在");
                }
            }
        }
        Apiinfoes apiinfoes = ApiinfoesHelper.createApiinfoes(request, "拨号");
        apiinfoesService.insert(ApiinfoesHelper.setApiinfoes(apiinfoes,
                AuthorizationToken + Produce.parmsToString("Calle164:" + Calle164, "Caller:" + Caller),
                GsonUtil.createJsonString(netState)));
        return netState;
    }

    // 微信端 获取回拨号码
    // 微信端 获取回拨号码
    @CrossOrigin
    @RequestMapping(value = "/wxCallBack", method = RequestMethod.POST)
    public @ResponseBody
    NetState wxCallBack(HttpServletRequest request, String Calle164, String Caller, String ParentId, String MobileNum,
                        Boolean stReturn, Double Longitude, Double Latitude, String IpAddress, String WxOpenId) throws Exception {
        NetState netState = new NetState();
        // 获取TOKEN
        String AuthorizationToken = null;
        AcessToken acesstoken = null;
        try {
            AuthorizationToken = request.getHeader("Authorization");
            if (AuthorizationToken != null && !AuthorizationToken.equals("")) {
                acesstoken = TokenUtils.getAcessToken(AuthorizationToken);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        String Mobile = null;
        String AgentID = null;
        if (acesstoken == null) {
            Mobile = MobileNum;
            AgentID = ParentId;
        } else {
            Mobile = acesstoken.getMobile();
            AgentID = acesstoken.getParentid();
        }

        String country = null;
        String province = null;
        String city = null;
        String area = null;
        if (Longitude != null && Latitude != null && IpAddress != null) {
            Map<String, Object> map = null;
            try {
                map = BaiduMapHelper.getCity(null, Latitude, Longitude);
                country = map.get("country").toString();
                province = map.get("province").toString();
                city = map.get("city").toString();
                area = map.get("district").toString();
            } catch (Exception e) {
                System.out.println("IP地址查询失败");
            }

            List<IpStored> ipStoreds = ipStoredService.selectByIpAddress(IpAddress);
            IpStored ipStored = new IpStored();
            if (ipStoreds != null && ipStoreds.size() > 0) {
                ipStored = ipStoreds.get(0);
                ipStored.setCountry(country);
                ipStored.setProvince(province);
                ipStored.setCity(city);
                ipStored.setArea(area);
                ipStoredService.updateByPrimaryKeySelective(ipStored);
            } else {
                ipStored.setIpaddress(IpAddress);
                ipStored.setCountry(country);
                ipStored.setProvince(province);
                ipStored.setCity(city);
                ipStored.setArea(area);
                ipStored.setCreatetime(Produce.getNowDate());
                ipStoredService.insertSelective(ipStored);
            }
        }

        // 校验传入参数
        if (AgentID == null || Calle164 == null || Caller == null || AgentID.equals("") || Calle164.equals("")
                || Caller.equals("")) {
            netState.setErrorCode(NetState.PARAMS_ERROR);
            netState.setData("参数异常");
        } else {
            if (!Mobile.equals(Caller)) {
                netState.setData("请填写签名号码");
                netState.setErrorCode(NetState.SIGN_ERROR);
                return netState;
            }
            String caller = Caller.trim().replace(" ", "");
            String calle164 = Calle164.trim().replace(" ", "").replace("+86", "").replace("-", "");
            if (caller.equals(calle164)) {
                netState.setErrorCode(NetState.PARAMS_ERROR);
                netState.setData("请勿拨打自己号码");
            } else {
                // 根据号码查询当前用户
                SubscribersExample subscribersExample = new SubscribersExample();
                subscribersExample.getOredCriteria().add(subscribersExample.createCriteria()
                        .andMobileEqualTo(Caller).andParentidEqualTo(AgentID).andDatastatusEqualTo(true));
                List<Subscribers> subscribers = subscribersService.selectByExample(subscribersExample);
                if (subscribers != null && subscribers.size() > 0) {
                    UsersExample agentsExample = new UsersExample();
                    agentsExample.getOredCriteria().add(agentsExample.createCriteria()
                            .andIdEqualTo(subscribers.get(0).getParentid()).andDatastatusEqualTo(true));
                    UsersExample shopsExample = new UsersExample();
                    shopsExample.getOredCriteria().add(shopsExample.createCriteria()
                            .andIdEqualTo(subscribers.get(0).getShopid()).andDatastatusEqualTo(true));
                    Users agent = null;
                    List<Users> agents = usersService.selectByExample(agentsExample);
                    Users shop = null;
                    List<Users> shops = usersService.selectByExample(shopsExample);
                    if (agents != null && agents.size() > 0) {
                        agent = agents.get(0);// 获取当前用户的上级代理
                    }
                    if (shops != null && shops.size() > 0) {
                        shop = shops.get(0);// 获取当前用户的商户
                    }
                    String uuid = Produce.getUUID();
                    String results = VosHelper.GetVosAccount("{accounts:['" + agent.getUsername() + "']}");
                    VosModelList v2 = GsonUtil.getObject(results, VosModelList.class);
                    String results1 = VosHelper.GetVosAccount(
                            "{accounts:['" + agent.getAgentprefix() + subscribers.get(0).getMobile() + "']}");
                    VosModelList v21 = GsonUtil.getObject(results1, VosModelList.class);
                    if (v2 != null && v2.retCode == 0) {
                        InfoCustomers info21 = v21.infoCustomers[0];
                        InfoCustomers info2 = v2.infoCustomers[0];
                        if (info21.getMoney().compareTo(new BigDecimal(0)) > 0) {
                            if (info2.getMoney().compareTo(new BigDecimal(0)) > 0
                                    || info2.getLimitMoney().compareTo(new BigDecimal(0)) > 0 || info2.getMoney()
                                    .compareTo(new BigDecimal(0).subtract(info2.getLimitMoney())) >= 0) {
                                Date endTime = new Date(info21.getValidTime());
                                if (Produce.getNowDate().before(endTime)) {
                                    if (stReturn != null && stReturn == false) {
                                        String cpResoult = CPHelper.getCall(request, caller, calle164);
                                        System.out.println(caller + "cp回调：" + cpResoult);
                                        JSONObject obj = JSONObject.fromObject(cpResoult);
                                        CP c1 = null;
                                        try {
                                            c1 = (CP) JSONObject.toBean(obj, CP.class);
                                            if (c1 != null) {
                                                if (c1.getCode() == 1) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            c1.getData().getOrderid(),
                                                            caller, calle164, Produce.getNowDate(), "提交CP线路",
                                                            agent.getId(), "CP线路提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                    // 如果接口线路出现异常走JH
                                                } else {
                                                    String resoult = CallHelper.getCall(request, caller, calle164);
                                                    Call cl = GsonUtil.getObject(resoult, Call.class);
                                                    if (cl != null) {
                                                        if (cl.getCode() == 1) {
                                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                    cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                                    caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                                    agent.getId(), "提交记录", Produce.getNowDate(),
                                                                    Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                    0, subscribers.get(0).getShopid()
                                                            );
                                                            callbackinfoes.setIpaddress(IpAddress);
                                                            callbackinfoes.setCountry(country);
                                                            callbackinfoes.setProvince(province);
                                                            callbackinfoes.setCity(city);
                                                            callbackinfoesService.insertSelective(callbackinfoes);
                                                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                                            netState.setData("正在接通中...");
                                                        } else {
                                                            callbackinfoesService.insert(uuid, caller, calle164,
                                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid());
                                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                            netState.setData("呼叫失败，运营商处出错");
                                                        }
                                                    }
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                        new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("呼叫失败，运营商处出错");
                                            }
                                            // st接口异常 直接进入ZP
                                        } catch (Exception e) {
                                            String resoult = CallHelper.getCall(request, caller, calle164);
                                            System.out.println(resoult);
                                            Call cl = GsonUtil.getObject(resoult, Call.class);
                                            if (cl != null) {
                                                if (cl.getCode() == 1) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                            caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                            agent.getId(), "提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                } else {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                            new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败，运营商处出错");
                                                }
                                            }
                                        }
                                    } else if (shop.getCalltype() == 1) {// 久话
                                        //如果是南海壹号则用总账号进行控制
//                                        if (shop.getParentid().equals("687f444917634ae9ab3d20e97c24ee8e")){
//                                            agent=usersService.selectByPrimaryKey("687f444917634ae9ab3d20e97c24ee8e");
//                                        }
//                                        String token = "JH " + JHHelper.getRedis();
//                                        String resoult = JHHelper.bh(caller, calle164, token, uuid);
                                        String token = "JH " + jhHelper.getRedisNew();
                                        String resoult = jhHelper.bhNew(caller, calle164, token, uuid);
                                        JH jh = GsonUtil.getObject(resoult, JH.class);
                                        if (jh != null) {
                                            if (jh.getResult() == 0) {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                                // 如果接口线路出现异常或者无可用路由等异常问题
                                            } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                    || jh.getResult() == 114 || jh.getResult() == 115
                                                    || jh.getResult() == 116) {
                                                // TODO 对接VOS接口
                                                String data1 = "";
                                                if (agent.getSxxh() != null || agent.getSxxh()) {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                } else {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                }
                                                String result = VosHelper.VosCallBack(data1);
                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                if (v1.retCode == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中，请注意接听回电...");
                                                } else if (v1.retCode == -2) {
                                                    callbackinfoesService.insert(uuid, caller, calle164,
                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                    netState.setData("余额不足");
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            } else if (jh.getResult() == 501) {
//                                                token = "JH " + JHHelper.getToken();// 服务端获取TOKEN
//                                                resoult = JHHelper.bh(caller, calle164, token, uuid);
                                                token = "JH " + jhHelper.getTokenNew();// 服务端获取TOKEN
                                                resoult = jhHelper.bhNew(caller, calle164, token, uuid);
                                                jh = GsonUtil.getObject(resoult, JH.class);
                                                if (jh.getResult() == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                        || jh.getResult() == 114 || jh.getResult() == 115
                                                        || jh.getResult() == 116) {
                                                    // TODO 对接VOS接口
                                                    String data1 = "";
                                                    if (agent.getSxxh() != null || agent.getSxxh()) {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"callerDisplayNumber\":\""
                                                                + Calle164 + "\",\"calleeE164s\":\""
                                                                + "1547448457"
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    } else {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"calleeE164s\":\""
                                                                + (Integer.parseInt("1547448456") + 1)
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    }
                                                    String result = VosHelper.VosCallBack(data1);
                                                    VosModelList v1 = GsonUtil.getObject(result,
                                                            VosModelList.class);
                                                    if (v1.retCode == 0) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中，请注意接听回电...");
                                                    } else if (v1.retCode == -2) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                        netState.setData("余额不足");
                                                    } else {
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败");
                                                    }
                                                } else {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("通话失败:" + jh.getMsg());
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData(jh.getMsg());
                                            }
                                        } else {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 2) {
                                        // TODO 对接VOS接口
                                        String data1 = "";
                                        if (agent.getSxxh() != null || agent.getSxxh()) {
                                            data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                    + "\",\"callerDisplayNumber\":\"" + Calle164
                                                    + "\",\"calleeE164s\":\""
                                                    + "1547448457" + Calle164
                                                    + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                        } else {
                                            data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                    + "\",\"calleeE164s\":\""
                                                    + (Integer.parseInt("1547448456") + 1) + Calle164
                                                    + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                        }
                                        String result = VosHelper.VosCallBack(data1);
                                        VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                        if (v1.retCode == 0) {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                            netState.setData("正在接通中...");
                                        } else if (v1.retCode == -2) {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                            netState.setData("余额不足");
                                        } else {
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败");
                                        }
                                    } else if (shop.getCalltype() == 3) {
                                        String resoult = CallHelper.getCall(request, caller, calle164);
                                        System.out.println(resoult);
                                        Call cl = GsonUtil.getObject(resoult, Call.class);
                                        if (cl != null) {
                                            if (cl.getCode() == 1) {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                        caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                        agent.getId(), "提交记录", Produce.getNowDate(),
                                                        Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                        0, subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                            } else {
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("受国家政策，通话功能国庆期间暂停服务，节后重新开通，给您带来不便，敬请谅解");
                                            }
//                                            else {
//                                                // TODO 对接VOS接口
//                                                String data1 = "";
//                                                if (agent.getSxxh() != null || agent.getSxxh()) {
//                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
//                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
//                                                            + "\",\"calleeE164s\":\""
//                                                            + "1547448457"
//                                                            + Calle164
//                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
//                                                } else {
//                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
//                                                            + "\",\"calleeE164s\":\""
//                                                            + (Integer.parseInt("1547448456") + 1)
//                                                            + Calle164
//                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
//                                                }
//                                                String result = VosHelper.VosCallBack(data1);
//                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
//                                                if (v1.retCode == 0) {
//                                                    callbackinfoesService.insert(uuid, caller, calle164,
//                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
//                                                            Produce.getNowDate(), Produce.getNowDate(),
//                                                            new BigDecimal(0), new BigDecimal(0), 0,
//                                                            subscribers.get(0).getShopid());
//                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
//                                                    netState.setData("正在接通中，请注意接听回电...");
//                                                } else if (v1.retCode == -2) {
//                                                    callbackinfoesService.insert(uuid, caller, calle164,
//                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
//                                                            Produce.getNowDate(), Produce.getNowDate(),
//                                                            new BigDecimal(0), new BigDecimal(0), 0,
//                                                            subscribers.get(0).getShopid());
//                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
//                                                    netState.setData("余额不足");
//                                                } else {
//                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
//                                                    netState.setData("呼叫失败");
//                                                }
//                                            }
                                        } else {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 4) {
                                        String stResoult = STHelper.getCall(request, caller, calle164);
//                                            ST sl = GsonUtil.getObject(stResoult, ST.class);
                                        System.out.println(caller + "回调：" + stResoult);
                                        JSONObject stObj = JSONObject.fromObject(stResoult);
                                        ST s1 = null;
                                        try {
                                            s1 = (ST) JSONObject.toBean(stObj, ST.class);
                                            if (s1 != null) {
                                                if (s1.getCode() == 1) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            s1.getData().getOrderid(),
                                                            caller, calle164, Produce.getNowDate(), "提交ST线路",
                                                            agent.getId(), "提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                    // 如果接口线路出现异常走CP
                                                } else {
                                                    String cpResoult = CPHelper.getCall(request, caller, calle164);
                                                    System.out.println(caller + "cp回调：" + cpResoult);
                                                    JSONObject cpObj = JSONObject.fromObject(cpResoult);
                                                    CP c1 = null;
                                                    try {
                                                        c1 = (CP) JSONObject.toBean(cpObj, CP.class);
                                                        if (c1 != null) {
                                                            if (c1.getCode() == 1) {
                                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                        c1.getData().getOrderid(),
                                                                        caller, calle164, Produce.getNowDate(), "提交CP线路",
                                                                        agent.getId(), "CP线路提交记录", Produce.getNowDate(),
                                                                        Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                        0, subscribers.get(0).getShopid()
                                                                );
                                                                callbackinfoes.setIpaddress(IpAddress);
                                                                callbackinfoes.setCountry(country);
                                                                callbackinfoes.setProvince(province);
                                                                callbackinfoes.setCity(city);
                                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                                netState.setData("正在接通中...");
                                                                // 如果接口线路出现异常走JH
                                                            } else {
                                                                String resoult = CallHelper.getCall(request, caller, calle164);
                                                                System.out.println(resoult);
                                                                Call cl = GsonUtil.getObject(resoult, Call.class);
                                                                if (cl != null) {
                                                                    if (cl.getCode() == 1) {
                                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                                cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                                                caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                                                agent.getId(), "提交记录", Produce.getNowDate(),
                                                                                Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                                0, subscribers.get(0).getShopid()
                                                                        );
                                                                        callbackinfoes.setIpaddress(IpAddress);
                                                                        callbackinfoes.setCountry(country);
                                                                        callbackinfoes.setProvince(province);
                                                                        callbackinfoes.setCity(city);
                                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                                        netState.setData("正在接通中...");
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    } catch (Exception e) {
                                                        String resoult = CallHelper.getCall(request, caller, calle164);
                                                        System.out.println(resoult);
                                                        Call cl = GsonUtil.getObject(resoult, Call.class);
                                                        if (cl != null) {
                                                            if (cl.getCode() == 1) {
                                                                callbackinfoesService.insert(
                                                                        cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                                        caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                                        agent.getId(), "提交记录", Produce.getNowDate(),
                                                                        Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                        0, subscribers.get(0).getShopid());
                                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                                netState.setData("正在接通中...");
                                                            }
                                                        }
                                                    }
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                        new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("呼叫失败，运营商处出错");
                                            }
                                            // st接口异常 直接进入CP
                                        } catch (Exception e) {
                                            String cpResoult = CPHelper.getCall(request, caller, calle164);
                                            System.out.println(caller + "cp回调：" + cpResoult);
                                            JSONObject cpObj = JSONObject.fromObject(cpResoult);
                                            CP c1 = null;
                                            try {
                                                c1 = (CP) JSONObject.toBean(cpObj, CP.class);
                                                if (c1 != null) {
                                                    if (c1.getCode() == 1) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                c1.getData().getOrderid(),
                                                                caller, calle164, Produce.getNowDate(), "提交CP线路",
                                                                agent.getId(), "CP线路提交记录", Produce.getNowDate(),
                                                                Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                0, subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中...");
                                                        // 如果接口线路出现异常走JH
                                                    } else {
                                                        String resoult = CallHelper.getCall(request, caller, calle164);
                                                        System.out.println(resoult);
                                                        Call cl = GsonUtil.getObject(resoult, Call.class);
                                                        if (cl != null) {
                                                            if (cl.getCode() == 1) {
                                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                        cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                                        caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                                        agent.getId(), "提交记录", Produce.getNowDate(),
                                                                        Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                        0, subscribers.get(0).getShopid()
                                                                );
                                                                callbackinfoes.setIpaddress(IpAddress);
                                                                callbackinfoes.setCountry(country);
                                                                callbackinfoes.setProvince(province);
                                                                callbackinfoes.setCity(city);
                                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                                netState.setData("正在接通中...");
                                                            }
                                                        } else {
                                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                    uuid, caller, calle164,
                                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                            );
                                                            callbackinfoes.setIpaddress(IpAddress);
                                                            callbackinfoes.setCountry(country);
                                                            callbackinfoes.setProvince(province);
                                                            callbackinfoes.setCity(city);
                                                            callbackinfoesService.insertSelective(callbackinfoes);
                                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                            netState.setData("呼叫失败，运营商处出错");
                                                        }
                                                    }
                                                }
                                            } catch (Exception ex) {
                                                String resoult = CallHelper.getCall(request, caller, calle164);
                                                System.out.println(resoult);
                                                Call cl = GsonUtil.getObject(resoult, Call.class);
                                                if (cl != null) {
                                                    if (cl.getCode() == 1) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                                caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                                agent.getId(), "提交记录", Produce.getNowDate(),
                                                                Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                0, subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中...");
                                                    } else {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                                new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败，运营商处出错");
                                                    }
                                                }
                                            }
                                        }
                                    } else if (shop.getCalltype() == 5) {
                                        String cpResoult = CPHelper.getCall(request, caller, calle164);
                                        System.out.println(caller + "cp回调：" + cpResoult);
                                        JSONObject obj = JSONObject.fromObject(cpResoult);
                                        CP c1 = null;
                                        try {
                                            c1 = (CP) JSONObject.toBean(obj, CP.class);
                                            if (c1 != null) {
                                                if (c1.getCode() == 1) {
                                                    callbackinfoesService.insert(
                                                            c1.getData().getOrderid(),
                                                            caller, calle164, Produce.getNowDate(), "提交CP线路",
                                                            agent.getId(), "CP线路提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                    // 如果接口线路出现异常走JH
                                                } else {
                                                    String resoult = CallHelper.getCall(request, caller, calle164);
                                                    System.out.println(resoult);
                                                    Call cl = GsonUtil.getObject(resoult, Call.class);
                                                    if (cl != null) {
                                                        if (cl.getCode() == 1) {
                                                            callbackinfoesService.insert(
                                                                    cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                                    caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                                    agent.getId(), "提交记录", Produce.getNowDate(),
                                                                    Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                                    0, subscribers.get(0).getShopid());
                                                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                                            netState.setData("正在接通中...");
                                                        } else {
                                                            callbackinfoesService.insert(uuid, caller, calle164,
                                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid());
                                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                            netState.setData("呼叫失败，运营商处出错");
                                                        }
                                                    }
                                                }
                                            } else {
                                                callbackinfoesService.insert(uuid, caller, calle164,
                                                        Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                        new BigDecimal(0), 0, subscribers.get(0).getShopid());
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("呼叫失败，运营商处出错");
                                            }
                                            // st接口异常 直接进入ZP
                                        } catch (Exception e) {
                                            String resoult = CallHelper.getCall(request, caller, calle164);
                                            System.out.println(resoult);
                                            Call cl = GsonUtil.getObject(resoult, Call.class);
                                            if (cl != null) {
                                                if (cl.getCode() == 1) {
                                                    callbackinfoesService.insert(
                                                            cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                            caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                            agent.getId(), "提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                } else {
                                                    callbackinfoesService.insert(uuid, caller, calle164,
                                                            Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                            new BigDecimal(0), 0, subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败，运营商处出错");
                                                }
                                            }
                                        }
                                    } else if (shop.getCalltype() == 6) {
                                        String cpResoult = XGJCPHelper.getCall(request, caller, calle164);
                                        System.out.println(caller + "cp回调：" + cpResoult);
                                        JSONObject obj = JSONObject.fromObject(cpResoult);
                                        CP c1 = null;
                                        try {
                                            c1 = (CP) JSONObject.toBean(obj, CP.class);
                                            if (c1 != null) {
                                                if (c1.getCode() == 1) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            c1.getData().getOrderid(),
                                                            caller, calle164, Produce.getNowDate(), "提交CP线路",
                                                            agent.getId(), "CP线路提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                        new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("呼叫失败，运营商处出错");
                                            }
                                            // st接口异常 直接进入ZP
                                        } catch (Exception e) {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 7) {// 久话
                                        String token = "JH " + bcJhHelper.getRedis();
                                        String resoult = BC_JHHelper.bh(caller, calle164, token, uuid);
                                        JH jh = GsonUtil.getObject(resoult, JH.class);
                                        if (jh != null) {
                                            if (jh.getResult() == 0) {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                                // 如果接口线路出现异常或者无可用路由等异常问题
                                            } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                    || jh.getResult() == 114 || jh.getResult() == 115
                                                    || jh.getResult() == 116) {
                                                // TODO 对接VOS接口
                                                String data1 = "";
                                                if (agent.getSxxh() != null || agent.getSxxh()) {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                } else {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                }
                                                String result = VosHelper.VosCallBack(data1);
                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                if (v1.retCode == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中，请注意接听回电...");
                                                } else if (v1.retCode == -2) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                    netState.setData("余额不足");
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            } else if (jh.getResult() == 501) {
                                                token = "JH " + bcJhHelper.getToken();// 服务端获取TOKEN
                                                resoult = BC_JHHelper.bh(caller, calle164, token, uuid);
                                                jh = GsonUtil.getObject(resoult, JH.class);
                                                if (jh.getResult() == 0) {
                                                    callbackinfoesService.insert(uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                        || jh.getResult() == 114 || jh.getResult() == 115
                                                        || jh.getResult() == 116) {
                                                    // TODO 对接VOS接口
                                                    String data1 = "";
                                                    if (agent.getSxxh() != null || agent.getSxxh()) {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"callerDisplayNumber\":\""
                                                                + Calle164 + "\",\"calleeE164s\":\""
                                                                + "1547448457"
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    } else {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"calleeE164s\":\""
                                                                + (Integer.parseInt("1547448456") + 1)
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    }
                                                    String result = VosHelper.VosCallBack(data1);
                                                    VosModelList v1 = GsonUtil.getObject(result,
                                                            VosModelList.class);
                                                    if (v1.retCode == 0) {
                                                        callbackinfoesService.insert(uuid, caller, calle164,
                                                                Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid());
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中，请注意接听回电...");
                                                    } else if (v1.retCode == -2) {
                                                        callbackinfoesService.insert(uuid, caller, calle164,
                                                                Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid());
                                                        netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                        netState.setData("余额不足");
                                                    } else {
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败");
                                                    }
                                                } else {
                                                    callbackinfoesService.insert(uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("通话失败:" + jh.getMsg());
                                                }
                                            } else {
                                                callbackinfoesService.insert(uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid());
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData(jh.getMsg());
                                            }
                                        } else {
                                            callbackinfoesService.insert(uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid());
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 8) {
                                        String resoult = XGJCPHelper.getZPCall(request, caller, calle164);
                                        System.out.println(resoult);
                                        Call cl = GsonUtil.getObject(resoult, Call.class);
                                        try {
                                            if (cl != null) {
                                                if (cl.getCode() == 1) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            cl.getData().trim().substring(cl.getData().indexOf(":") + 2, cl.getData().indexOf(",") - 1),
                                                            caller, calle164, Produce.getNowDate(), cl.getMessage(),
                                                            agent.getId(), "提交记录", Produce.getNowDate(),
                                                            Produce.getNowDate(), new BigDecimal(0), new BigDecimal(0),
                                                            0, subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                        new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData("呼叫失败，运营商处出错");
                                            }
                                            // st接口异常 直接进入ZP
                                        } catch (Exception e) {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 9) {
                                        if (Longitude == null || Latitude == null) {
                                            netState.setErrorCode(NetState.UNKNOWN_IP);
                                            netState.setData("请先授权定位，旧版本请立即升级新版");
                                            return netState;
                                        }
                                        if (WxOpenId == null || WxOpenId.equals("")) {
                                            if (subscribers.get(0).getWxopenid() == null || subscribers.get(0).getWxopenid().equals("")) {
                                                netState.setErrorCode(NetState.WX_OPENID_UNBOUND);
                                                netState.setData("请退出当前登录，使用微信授权登陆绑定您的信息后使用");
                                                return netState;
                                            } else {
                                                WxOpenId = subscribers.get(0).getWxopenid();
                                            }
                                        }

                                        String token = "JH " + jhHelper.getRedisNew();
                                        String resoult = jhHelper.bhNew(caller, calle164, token, uuid);
//                                        String token = "JH " + JHHelper.getRedisNew();
//                                        String resoult = JHHelper.bhNew(caller, calle164, token, uuid);
                                        JH jh = GsonUtil.getObject(resoult, JH.class);
                                        if (jh != null) {
                                            if (jh.getResult() == 0) {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoes.setWxopenid(WxOpenId);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                                // 如果接口线路出现异常或者无可用路由等异常问题
                                            } else if (jh.getResult() == 101 || jh.getResult() == 124) {
                                                String tokenNew = "JH " + jhHelper.getRedisNew();
                                                String resoultNew = jhHelper.bhNew(caller, calle164, tokenNew, uuid);
                                                JH jhNew = GsonUtil.getObject(resoultNew, JH.class);
                                                if (jhNew != null) {
                                                    if (jhNew.getResult() == 0) {
                                                        Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                                uuid, caller, calle164,
                                                                Produce.getNowDate(), jhNew.getMsg(), agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid()
                                                        );
                                                        callbackinfoes.setIpaddress(IpAddress);
                                                        callbackinfoes.setCountry(country);
                                                        callbackinfoes.setProvince(province);
                                                        callbackinfoes.setCity(city);
                                                        callbackinfoesService.insertSelective(callbackinfoes);
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中...");
                                                        // 如果接口线路出现异常或者无可用路由等异常问题
                                                    } else {
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败");
                                                    }
                                                }
                                            } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                    || jh.getResult() == 114 || jh.getResult() == 115
                                                    || jh.getResult() == 116) {
                                                // TODO 对接VOS接口
                                                String data1 = "";
                                                if (agent.getSxxh() != null || agent.getSxxh()) {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                } else {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                }
                                                String result = VosHelper.VosCallBack(data1);
                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                if (v1.retCode == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中，请注意接听回电...");
                                                } else if (v1.retCode == -2) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                    netState.setData("余额不足");
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            } else if (jh.getResult() == 501) {
                                                log.warn("[结果501]");
                                                token = "JH " + jhHelper.getTokenNew();// 服务端获取TOKEN
                                                resoult = jhHelper.bhNew(caller, calle164, token, uuid);
//                                                token = "JH " + JHHelper.getTokenNew();// 服务端获取TOKEN
//                                                resoult = JHHelper.bhNew(caller, calle164, token, uuid);
                                                jh = GsonUtil.getObject(resoult, JH.class);
                                                if (jh.getResult() == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                        || jh.getResult() == 114 || jh.getResult() == 115
                                                        || jh.getResult() == 116) {
                                                    // TODO 对接VOS接口
                                                    String data1 = "";
                                                    if (agent.getSxxh() != null || agent.getSxxh()) {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"callerDisplayNumber\":\""
                                                                + Calle164 + "\",\"calleeE164s\":\""
                                                                + "1547448457"
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    } else {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"calleeE164s\":\""
                                                                + (Integer.parseInt("1547448456") + 1)
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    }
                                                    String result = VosHelper.VosCallBack(data1);
                                                    VosModelList v1 = GsonUtil.getObject(result,
                                                            VosModelList.class);
                                                    if (v1.retCode == 0) {
                                                        callbackinfoesService.insert(uuid, caller, calle164,
                                                                Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid());
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中，请注意接听回电...");
                                                    } else if (v1.retCode == -2) {
                                                        callbackinfoesService.insert(uuid, caller, calle164,
                                                                Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid());
                                                        netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                        netState.setData("余额不足");
                                                    } else {
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败");
                                                    }
                                                } else {
                                                    callbackinfoesService.insert(uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("通话失败:" + jh.getMsg());
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData(jh.getMsg());
                                            }
                                        } else {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 10) {// 久话自定义custom
                                        String token = "JH " + jhHelper.getRedisCustom(shop);
                                        String resoult = jhHelper.bhCustom(shop, caller, calle164, token, uuid, IpAddress);
                                        JH jh = GsonUtil.getObject(resoult, JH.class);
                                        if (jh != null) {
                                            if (jh.getResult() == 0) {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                                // 如果接口线路出现异常或者无可用路由等异常问题
                                            } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                    || jh.getResult() == 114 || jh.getResult() == 115
                                                    || jh.getResult() == 116) {
                                                // TODO 对接VOS接口
                                                String data1 = "";
                                                if (agent.getSxxh() != null || agent.getSxxh()) {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                } else {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                }
                                                String result = VosHelper.VosCallBack(data1);
                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                if (v1.retCode == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中，请注意接听回电...");
                                                } else if (v1.retCode == -2) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                    netState.setData("余额不足");
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            } else if (jh.getResult() == 501) {
                                                token = "JH " + jhHelper.getTokenCustom(shop);// 服务端获取TOKEN
                                                resoult = jhHelper.bhCustom(shop, caller, calle164, token, uuid, IpAddress);
                                                jh = GsonUtil.getObject(resoult, JH.class);
                                                if (jh.getResult() == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中...");
                                                } else if (jh.getResult() == 101 || jh.getResult() == 105
                                                        || jh.getResult() == 114 || jh.getResult() == 115
                                                        || jh.getResult() == 116) {
                                                    // TODO 对接VOS接口
                                                    String data1 = "";
                                                    if (agent.getSxxh() != null || agent.getSxxh()) {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"callerDisplayNumber\":\""
                                                                + Calle164 + "\",\"calleeE164s\":\""
                                                                + "1547448457"
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    } else {
                                                        data1 = "{\"callerE164\":\"" + "1547448456"
                                                                + Caller + "\",\"calleeE164s\":\""
                                                                + (Integer.parseInt("1547448456") + 1)
                                                                + Calle164
                                                                + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                    }
                                                    String result = VosHelper.VosCallBack(data1);
                                                    VosModelList v1 = GsonUtil.getObject(result,
                                                            VosModelList.class);
                                                    if (v1.retCode == 0) {
                                                        callbackinfoesService.insert(uuid, caller, calle164,
                                                                Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid());
                                                        netState.setErrorCode(NetState.SUCCESS_CONN);
                                                        netState.setData("正在接通中，请注意接听回电...");
                                                    } else if (v1.retCode == -2) {
                                                        callbackinfoesService.insert(uuid, caller, calle164,
                                                                Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                                Produce.getNowDate(), Produce.getNowDate(),
                                                                new BigDecimal(0), new BigDecimal(0), 0,
                                                                subscribers.get(0).getShopid());
                                                        netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                        netState.setData("余额不足");
                                                    } else {
                                                        netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                        netState.setData("呼叫失败");
                                                    }
                                                } else {
                                                    callbackinfoesService.insert(uuid, caller, calle164,
                                                            Produce.getNowDate(), jh.getMsg(), agent.getId(),
                                                            "提交记录", Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid());
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("通话失败:" + jh.getMsg());
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jh.getMsg(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData(jh.getMsg());
                                            }
                                        } else {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else if (shop.getCalltype() == 11) {
                                        // SC线路通话:
                                        String token = SCHelper.getToken();
                                        String resoult = SCHelper.BeginCall(caller, calle164, token, uuid);
                                        SC sc = GsonUtil.getObject(resoult, SC.class);
                                        if (sc != null) {
                                            //token 过期时候的处理方式 刷新授权
                                            if (sc.getResultcode().equals("1010005") || sc.getResultcode().equals("1010004")) {


                                            }
                                            if (sc.getResultcode().equals("0")) {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), sc.getResultcode(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                                // 如果接口线路出现异常或者无可用路由等异常问题
                                            } else if (sc.getResultcode().equals("1010001") || sc.getResultcode().equals("1020001")
                                                    || sc.getResultcode().equals("1020002") || sc.getResultcode().equals("1020150")
                                                    || sc.getResultcode().equals("1020154")) {
                                                // TODO 对接VOS接口
                                                String data1 = "";
                                                if (agent.getSxxh() != null || agent.getSxxh()) {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                } else {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                }
                                                String result = VosHelper.VosCallBack(data1);
                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                if (v1.retCode == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中，请注意接听回电...");
                                                } else if (v1.retCode == -2) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                    netState.setData("余额不足");
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            } else {
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), sc.getResultcode(), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                netState.setData(sc.getResultdesc());
                                            }
                                        }
                                    } else if (shop.getCalltype() == 12) {
                                        uuid = ServiceUrls.servicePrefix + uuid;
                                        //云讯科技
                                        JSONObject jsonObject = ZJYCallHelper.httpPhone(caller, calle164, "86164", uuid);
                                        if (jsonObject != null) {
                                            //如果是线路饱满，则重试5次
                                            int count = 5;
                                            while (jsonObject.getString("statusCode").equals("-104") && count > 0) {
                                                jsonObject = ZJYCallHelper.httpPhone(caller, calle164, "86164", uuid);
                                                count--;
                                            }
                                            if (jsonObject.getString("statusCode").equals("200")) {
                                                log.warn("呼叫成功");
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jsonObject.getString("statusCode"), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                                // 如果接口线路出现异常或者无可用路由等异常问题
                                            } else {
                                                // TODO 对接VOS接口
                                                String data1 = "";
                                                if (agent.getSxxh() != null || agent.getSxxh()) {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                } else {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                }
                                                String result = VosHelper.VosCallBack(data1);
                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                if (v1.retCode == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中，请注意接听回电...");
                                                } else if (v1.retCode == -2) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                    netState.setData("余额不足");
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            }
                                        } else {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    }else if(shop.getCalltype() == 13){
                                        uuid = ServiceUrls.servicePrefix + uuid;
                                        String result1="";
                                        try{
                                            result1=  SCZHHelper.callPhone(caller,calle164,uuid);
                                        }catch (Exception e){
                                            return new NetState(NetState.ACCOUNT_ERROR,"无法转到回拨线路");
                                        }

                                        com.alibaba.fastjson.JSONObject jsonObject= com.alibaba.fastjson.JSONObject.parseObject(result1);
                                        if (jsonObject != null) {
                                            //token 过期时候的处理方式 刷新授权
//                                                if (sc.getResultcode().equals("1010005") || sc.getResultcode().equals("1010004")) {
//                                                }

                                            if (jsonObject.getString("errno").equals("0")) {
                                                log.warn("呼叫成功");
                                                Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                        uuid, caller, calle164,
                                                        Produce.getNowDate(), jsonObject.getString("statusCode"), agent.getId(), "提交记录",
                                                        Produce.getNowDate(), Produce.getNowDate(),
                                                        new BigDecimal(0), new BigDecimal(0), 0,
                                                        subscribers.get(0).getShopid()
                                                );
                                                callbackinfoes.setIpaddress(IpAddress);
                                                callbackinfoes.setCountry(country);
                                                callbackinfoes.setProvince(province);
                                                callbackinfoes.setCity(city);
                                                callbackinfoesService.insertSelective(callbackinfoes);
                                                netState.setErrorCode(NetState.SUCCESS_CONN);
                                                netState.setData("正在接通中...");
                                                // 如果接口线路出现异常或者无可用路由等异常问题
                                            } else {
                                                // TODO 对接VOS接口
                                                String data1 = "";
                                                if (agent.getSxxh() != null || agent.getSxxh()) {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"callerDisplayNumber\":\"" + Calle164
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                } else {
                                                    data1 = "{\"callerE164\":\"" + "1547448456" + Caller
                                                            + "\",\"calleeE164s\":\""
                                                            + "1547448457"
                                                            + Calle164
                                                            + "\",\"accessE164\":\"19989\",\"accessE164Password\":\"IPZXOcFE\"}";
                                                }
                                                String result = VosHelper.VosCallBack(data1);
                                                VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                                if (v1.retCode == 0) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.SUCCESS_CONN);
                                                    netState.setData("正在接通中，请注意接听回电...");
                                                } else if (v1.retCode == -2) {
                                                    Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                            uuid, caller, calle164,
                                                            Produce.getNowDate(), "余额不足", agent.getId(), "提交记录",
                                                            Produce.getNowDate(), Produce.getNowDate(),
                                                            new BigDecimal(0), new BigDecimal(0), 0,
                                                            subscribers.get(0).getShopid()
                                                    );
                                                    callbackinfoes.setIpaddress(IpAddress);
                                                    callbackinfoes.setCountry(country);
                                                    callbackinfoes.setProvince(province);
                                                    callbackinfoes.setCity(city);
                                                    callbackinfoesService.insertSelective(callbackinfoes);
                                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                                    netState.setData("余额不足");
                                                } else {
                                                    netState.setErrorCode(NetState.SYSTEM_ERROR);
                                                    netState.setData("呼叫失败");
                                                }
                                            }
                                        } else {
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    }else if(shop.getCalltype() == 14){
                                        if(StringUtils.isEmpty(IpAddress)){
                                            IpAddress="192.168.10.33";
                                        }
                                        String result=CallHelper14.doCall(caller,calle164,IpAddress,uuid);
                                        log.warn("14号线路拨号:"+result);
                                        com.alibaba.fastjson.JSONObject res= JSON.parseObject(result);
                                        if(res.getString("code").equals("1")){
                                            log.warn("14号线路拨通成功");
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "呼叫成功", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(),
                                                    new BigDecimal(0), new BigDecimal(0), 0,
                                                    subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                            netState.setData("正在接通中，请注意接听回电...");
                                        }else {
                                            log.warn("拨号失败"+result);
                                            Callbackinfoes callbackinfoes = new Callbackinfoes(
                                                    uuid, caller, calle164,
                                                    Produce.getNowDate(), "运营商处出错", agent.getId(), "提交记录",
                                                    Produce.getNowDate(), Produce.getNowDate(), new BigDecimal(0),
                                                    new BigDecimal(0), 0, subscribers.get(0).getShopid()
                                            );
                                            callbackinfoes.setIpaddress(IpAddress);
                                            callbackinfoes.setCountry(country);
                                            callbackinfoes.setProvince(province);
                                            callbackinfoes.setCity(city);
                                            callbackinfoesService.insertSelective(callbackinfoes);
                                            netState.setErrorCode(NetState.SYSTEM_ERROR);
                                            netState.setData("呼叫失败，运营商处出错");
                                        }
                                    } else {
                                        netState.setErrorCode(NetState.FEAILED);
                                        netState.setData("该用户没有指定的拨号方式");
                                    }
                                } else {
                                    netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                    netState.setData("您的账户已经过期");
                                }
                            } else {
                                netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                                netState.setData("线路暂时无法使用");
                            }
                        } else {
                            netState.setErrorCode(NetState.AMOUNT_NOT_QUERY);
                            netState.setData("余额不足");
                        }
                    }
                    /**** 上述内容需要代理商有话费、用户有话费 ****/
                    /**** 上述内容需要代理商线路以及账户正常 ****/
                } else {
                    netState.setErrorCode(NetState.NODATA);
                    netState.setData("用户不存在");
                }
            }
        }
        Apiinfoes apiinfoes = ApiinfoesHelper.createApiinfoes(request, "拨号");
        apiinfoesService.insert(ApiinfoesHelper.setApiinfoes(apiinfoes,
                AuthorizationToken + Produce.parmsToString("Calle164:" + Calle164, "Caller:" + Caller),
                GsonUtil.createJsonString(netState)));
        return netState;
    }

    /**
     * 久话话单推送
     *
     * @param request
     * @param requestJson
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/JHpush", method = RequestMethod.POST)
    public @ResponseBody
    NetState JHpush(HttpServletRequest request, @RequestBody String requestJson) throws Exception {
        NetState netState = new NetState();

        // TODO requestJson = "{\"App_id\": 20151,\"Call_answertime\":
        // \"2018-05-28
        // 21:14:59\",\"Call_bill\": 0.12,\"Call_duration\":
        // 79,\"Call_endtime\": \"2018-05-28 21:16:18\",\"Call_id\":
        // \"aa57b8df16ac45b580272ab266186d1a\",\"Call_starttime\": \"2018-05-28
        // 18:57:32\",\"Callee\": \"+8618867860012\",\"Caller\":
        // \"+8615168269848\",\"Request_time\": \"2018-05-28
        // 21:14:47\",\"Extends\":\" \"}";
        Apiinfoes apiinfoes = ApiinfoesHelper.createApiinfoes(request, "久话线路话单");
        apiinfoesService
                .insert(ApiinfoesHelper.setApiinfoes(apiinfoes, requestJson, GsonUtil.createJsonString(netState)));
        // 1.解析返回参数（JHRESULT）
        JHresult call = GsonUtil.getObject(requestJson, JHresult.class);
        if (call != null) {
            call.Callee = call.Callee.replace("+86", "").trim(); // 被叫
            call.Caller = call.Caller.replace("+86", "").trim(); // 主叫
            // 2. 查询该话单
            Callbackinfoes callbackinfoes = callbackinfoesService.selectByPrimaryKey(call.Call_id);
            if (callbackinfoes != null) {
                // a.若存在此话单进行更新
                if (call.Call_duration == 0) {
                    // a.0时长直接更新话单
                    callbackinfoes.setSysnum("JH推送话单");
                    callbackinfoes.setCalltime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Request_time));
                    callbackinfoes.setEndtime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Request_time));
                    callbackinfoes.setFwdtime(Produce.getNowDate());
                    callbackinfoes.setMoney(new BigDecimal(0));
                    callbackinfoes.setOmoney(new BigDecimal(0));
                    callbackinfoes.setTimecount(0);
                    callbackinfoes.setStatus("未接通");
                    callbackinfoesService.updateByPrimaryKeySelective(callbackinfoes);
                    netState.setErrorCode(NetState.SUCCESS_CONN);
                    netState.setData("成功更新订单");
                    System.out.println("成功更新订单");
                } else {
                    // b.非0时长
                    float mins = (float) call.Call_duration / 60;
                    double secound = Math.ceil(mins);// 分钟数
                    // 查询该用户
                    SubscribersExample subscribersExample = new SubscribersExample();
                    subscribersExample.getOredCriteria()
                            .add(subscribersExample.createCriteria().andMobileEqualTo(call.Caller)
                                    .andParentidEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                    List<Subscribers> subs = subscribersService.selectByExample(subscribersExample);
                    Subscribers user = null;
                    // 查询该代理
                    UsersExample usersExample = new UsersExample();
                    usersExample.getOredCriteria().add(usersExample.createCriteria()
                            .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                    List<Users> users = usersService.selectByExample(usersExample);
                    Users agent = null;
                    // VOS查询该账号
                    if ((subs != null && subs.size() == 1) && (users != null && users.size() == 1)) {
                        user = subs.get(0);
                        agent = users.get(0);

                        // 查询分享者 变更前话费余额
                        BigDecimal beforeB = new BigDecimal(0);
                        //备注
                        String remark = null;
                        try {
                            // TODO 暂时配注
                            String userR = VosHelper
                                    .GetVosAccount("{accounts:['" + agent.getAgentprefix() + user.getMobile() + "']}");
                            if (userR != null) {
                                VosModelList userR1 = GsonUtil.getObject(userR, VosModelList.class);
                                if (userR1.retCode == 0) {
                                    beforeB = userR1.infoCustomers[0].getMoney();
                                } else {
                                    beforeB = new BigDecimal(0);
                                    remark = "暂无记录";
                                }
                            }
                        } catch (Exception e) {
                            beforeB = new BigDecimal(0);
                            remark = "暂无记录";
                        }
                        // 变更话费金额
                        BigDecimal changeB = new BigDecimal(0);

                        // TODO 查询费率
                        // String results = VosHelper
                        // .GetVosAccount("{accounts:['" +
                        // agent.getAgentprefix() + user.getMobile() + "']}");
                        // VosModelList v1 = GsonUtil.getObject(results,
                        // VosModelList.class);
                        // String fe = v1.infoCustomers[0].feeRateGroup;
                        // System.out.println(fe);
                        Freeroutes f = null;
                        String freeroute = agent.getFreeroute();
                        // TODO 费率组检测
                        if (freeroute.contains("随便打") || freeroute.contains("季卡") || freeroute.contains("月卡") || freeroute.contains("0.25")) {
                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.25), true, 60,
                                    Produce.getNowDate());
                        } else if (freeroute.contains("0.2") || freeroute.contains("年卡")) {
                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.2), true, 60,
                                    Produce.getNowDate());
                        } else if (freeroute.contains("0.3")) {
                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.3), true, 60,
                                    Produce.getNowDate());
                        } else if (freeroute.contains("高频") || freeroute.contains("乐淘通") || freeroute.contains("0.6")) {
                            f = new Freeroutes(Produce.getUUID(), "高频用户", new BigDecimal(0.6), true, 60,
                                    Produce.getNowDate());
                        } else {
                            FreeroutesExample freeroutesExample = new FreeroutesExample();
                            freeroutesExample.getOredCriteria().add(freeroutesExample.createCriteria()
                                    .andNameLike("%" + freeroute + "%").andDatastatusEqualTo(true));
                            List<Freeroutes> freeroutes = freeroutesService.selectByExample(freeroutesExample);
                            if (freeroutes != null && freeroutes.size() > 0) {
                                f = freeroutes.get(0);
                            }
                        }

                        if (f != null) {
                            //???
                            if (f.getRatelength() != 60) {
                                float min = (float) call.Call_duration / f.getRatelength();
                                secound = Math.ceil(min);// 分钟数
                            }
                            // 计算费用
                            BigDecimal money = f.getFeelroute().multiply(new BigDecimal(secound)); // 费用
                            changeB = money;
                            BigDecimal fl = JHHelper.JH;
                            BigDecimal omon = fl.multiply(new BigDecimal(secound));
                            System.out.println("secound:" + secound + "money:" + money + "omon:" + omon);
                            // 进行扣费
                            if (user.getType() == 7) {
                                if (user.getParentid().equals("687f444917634ae9ab3d20e97c24ee8e")) { //如果是南海一号进行独特的扣费逻辑
                                    int value = money.multiply(new BigDecimal("10.00")).intValue();
                                    int oldMoney = user.getShopBalance();
                                    String result = VosHelper.GetVosAccount("{accounts:['" + agent.getAgentprefix() + user.getMobile() + "']}");
                                    VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                    BigDecimal balance = v1.infoCustomers[0].money; // 用户余额
                                    //进行判断
                                    if (oldMoney >= value) {
                                        user.setShopBalance(oldMoney - value);
                                        subscribersService.updateByPrimaryKeySelective(user);
                                    } else {
                                        UsersExample listsExample = new UsersExample();
                                        listsExample.getOredCriteria().add(listsExample.createCriteria()
                                                .andIdEqualTo(user.getShopid()).andDatastatusEqualTo(true));
                                        List<Users> lists = usersService.selectByExample(listsExample);
                                        Users list = null;
                                        UsersExample agents1sExample = new UsersExample();
                                        agents1sExample.getOredCriteria().add(agents1sExample.createCriteria()
                                                .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                                        List<Users> agents1s = usersService.selectByExample(agents1sExample);
                                        Users agents1 = null;
                                        if ((lists != null && lists.size() == 1)
                                                || (agents1s != null && agents1s.size() == 1)) {
                                            list = lists.get(0);
                                            agents1 = agents1s.get(0);
                                            VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getAgentprefix()
                                                    + callbackinfoes.getCaller() + "\",\"ownerType\":\"2\",\"money\":\"-"
                                                    + money + "\",\"memo\":\"用户通话扣费:" + money + "元\"}");
                                            VosHelper.PayVosAccount("{\"ownerName\":\"" + list.getUsername()
                                                    + "\",\"ownerType\":\"2\",\"money\":\"-" + money + "\",\"memo\":\"用户通话扣费:"
                                                    + money + "元\"}");
                                            VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getUsername()
                                                    + "j\",\"ownerType\":\"2\",\"money\":\"-" + omon + "\",\"memo\":\"用户通话扣线路费:"
                                                    + omon + "元\"}");
                                        }
                                        callbackinfoes.setMoney(money);
                                    }
                                    //正常用户扣费逻辑
                                } else {
                                    UsersExample listsExample = new UsersExample();
                                    listsExample.getOredCriteria().add(listsExample.createCriteria()
                                            .andIdEqualTo(user.getShopid()).andDatastatusEqualTo(true));
                                    List<Users> lists = usersService.selectByExample(listsExample);
                                    Users list = null;
                                    UsersExample agents1sExample = new UsersExample();
                                    agents1sExample.getOredCriteria().add(agents1sExample.createCriteria()
                                            .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                                    List<Users> agents1s = usersService.selectByExample(agents1sExample);
                                    Users agents1 = null;
                                    if ((lists != null && lists.size() == 1)
                                            || (agents1s != null && agents1s.size() == 1)) {
                                        list = lists.get(0);
                                        agents1 = agents1s.get(0);
                                        VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getAgentprefix()
                                                + callbackinfoes.getCaller() + "\",\"ownerType\":\"2\",\"money\":\"-"
                                                + money + "\",\"memo\":\"用户通话扣费:" + money + "元\"}");
                                        VosHelper.PayVosAccount("{\"ownerName\":\"" + list.getUsername()
                                                + "\",\"ownerType\":\"2\",\"money\":\"-" + money + "\",\"memo\":\"用户通话扣费:"
                                                + money + "元\"}");
                                        VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getUsername()
                                                + "j\",\"ownerType\":\"2\",\"money\":\"-" + omon + "\",\"memo\":\"用户通话扣线路费:"
                                                + omon + "元\"}");
                                    }
                                    callbackinfoes.setMoney(money);
                                }
                            } else {
                                callbackinfoes.setMoney(new BigDecimal(0));
                            }
                            // 更新话单
                            callbackinfoes.setSysnum("JH推送话单");
                            callbackinfoes
                                    .setCalltime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Request_time));
                            callbackinfoes
                                    .setEndtime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Request_time));
                            callbackinfoes.setFwdtime(
                                    new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Call_answertime));
                            callbackinfoes.setOmoney(omon);
                            callbackinfoes.setTimecount(call.Call_duration);
                            callbackinfoes.setStatus("接通");
                            callbackinfoesService.updateByPrimaryKeySelective(callbackinfoes);
                            Long calltime = 0L;
                            Long endTime = 0L;
                            Long fwdTime = 0L;
                            //淘时代回调
                            if (agent.getId().equals("6892db9945474dc6bc5004a8f5b9d0f9")) {
                                calltime = callbackinfoes.getCalltime().getTime();
                                endTime = callbackinfoes.getEndtime().getTime();
                                fwdTime = callbackinfoes.getFwdtime().getTime();
                                callbackinfoes.setCalltimeStr(calltime);
                                callbackinfoes.setEndTimeStr(endTime);
                                callbackinfoes.setFwdTimeStr(fwdTime);
                                String get = JSONObject.fromObject(callbackinfoes).toString();
                                String result = WebHelper.PostData("http://tsd.lk99.cn/app/tel/telHang?param=" + encode(get, "utf-8") + "&sign=bGlhbmthaml0dWFuODg420", null, "application/x-www-form-urlencoded", null);
                                System.out.println("接口返回值" + result);
                            }else if (agent.getId().equals("875ebeb6fe52464ca8c9c418199e774b")) {
                                String get = JSONObject.fromObject(callbackinfoes).toString();
                                String result = WebHelper.PostData("http://car-clue.ruiqinet.com/car_clue/App/call_back?param=" + encode(get, "GBK"), null, "application/x-www-form-urlencoded", null);
                                System.out.println("接口返回值" + result);
                            }else if(agent.getId().equals("13715e2af9b24f55ab24773101688490")){
                                callbackinfoes.setOmoney(null);
                                String get = JSONObject.fromObject(callbackinfoes).toString();
                                try {
                                    String url = "https://fztuanpinbao.com/sbd/callback?str=" + encode(get, "utf-8");
                                    DelayOrderWorker work = new DelayOrderWorker(url, null, 3);
                                    DelayOrderQueueManager manager = DelayOrderQueueManager.getInstance();
                                    manager.put(work, 0, TimeUnit.MILLISECONDS);
                                } catch (UnsupportedEncodingException e) {
                                    e.printStackTrace();
                                    log.error("error call" + e.getMessage());
                                }
                            }else if(agent.getId().equals("0f5b422825c041049c48d8baaf184bb5") || agent.getId().equals("be231a9a1edc4b549b60ab7a84a62bc4")|| agent.getId().equals("762dcf2a9ec241f0b3fc95772424d9c1")) {
                                //首享话单推送
                                callbackinfoes.setOmoney(null);
                                String get = JSONObject.fromObject(callbackinfoes).toString();
                                String key = "514b35da529ecf0f0ebfa76f54aa5699";
                                String sign = MD5Util.MD5Encode(get + key, "UTF-8").toLowerCase();
                                String param1 = "suiBianDaCallBillCallback=" + get + "&sign=" + sign;
                                String result = null;
                                try {
                                    String url = "http://api.daniaodianhua.com/callback/suibianda?suiBianDaCallBillCallback=" + encode(get, "utf-8") + "&sign=" + sign;
                                    DelayOrderWorker work = new DelayOrderWorker(url, null, 3);
                                    DelayOrderQueueManager manager = DelayOrderQueueManager.getInstance();
                                    manager.put(work, 3000, TimeUnit.MILLISECONDS);
                                } catch (UnsupportedEncodingException e) {
                                    e.printStackTrace();
                                    log.error("error call" + e.getMessage());
                                }
//                                    log.warn("callback" + callbackinfoes.getCaller() + "result:" + result);
                            }else{
                                try{
                                    log.warn("[OEM回调]");
                                    CallbackRedirectTable callbackRedirectTable=  callbackRedirectTableService.selectByUserId(agent.getId());
                                    if(callbackRedirectTable!=null && !StringUtils.isEmpty(callbackRedirectTable.getRedirectUrl())){
                                        String url=callbackRedirectTable.getRedirectUrl().trim();
                                        log.warn("[OEM回调]回调地址:"+url);
                                        com.alibaba.fastjson.JSONObject backUrl= SBDUtil.callbackbyurl(callbackinfoes);
                                        log.warn("[OEM回调] 获取新的回调数据"+JSON.toJSONString(backUrl));
                                        SbdCallBackWorker2 work = new SbdCallBackWorker2(url, backUrl);
                                        DelayOrderQueueManager manager = DelayOrderQueueManager.getInstance();
                                        manager.put(work, 0, TimeUnit.MILLISECONDS);
                                        log.warn("[OEM回调] 已发送回调:"+backUrl.toString());
                                    }
                                }catch (Exception e){
                                    log.warn("回调失败:"+e.toString());
                                    log.warn("回调失败:"+agent.getUsername());
                                }

                            }

                            try {
                                // 话费变更记录
                                changeRecordService.insertSelective(new ChangeRecord(user.getParentid(), user.getShopid(), user.getId(),
                                        Produce.getNowDate(), beforeB, changeB, 0, user.getEndtime(), user.getEndtime(), "拨打电话",
                                        BigDecimal.valueOf(user.getShopBalance()), BigDecimal.valueOf(0), 0,
                                        new SimpleDateFormat("yyyy-MM-dd").parse(user.getShopEnddate()),
                                        new SimpleDateFormat("yyyy-MM-dd").parse(user.getShopEnddate()), "拨打电话", remark));
                            } catch (Exception e) {
                                logsService.insert(CommContent.TYPE_CREATE, user.getMobile() + "拨打电话余额变更记录异常", agent.getUsername(), true,
                                        IP.getIpAddr(request));
                            }

                            netState.setErrorCode(NetState.SUCCESS_CONN);
                            netState.setData("成功更新订单");
                            System.out.println("成功更新订单");
                        } else {
                            netState.setErrorCode(NetState.NODATA);
                            netState.setData("无法匹配此费率");
                            System.out.println("无法匹配此费率");
                        }
                    } else {
                        netState.setErrorCode(NetState.NODATA);
                        netState.setData("用户或者代理不存在");
                        System.out.println("用户或者代理不存在");
                    }
                }
            } else {
                netState.setErrorCode(NetState.NODATA);
                netState.setData("话单不存在");
                System.out.println("话单不存在");
            }
        } else {
            netState.setErrorCode(NetState.SYSTEM_ERROR);
            netState.setData("话单返回值解析失败");
            System.out.println("话单返回值解析失败");
        }
        return netState;
    }


    @RequestMapping(value = "/SCPush", method = RequestMethod.POST)
    public @ResponseBody
    String SCPush(HttpServletRequest request) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
        String message = org.apache.commons.io.IOUtils.toString(reader);
        log.warn("SC话单回调:" + message);
        com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(message);
        if (!jsonObject.getString("eventType").equals("fee")) {
            //非话单事件
            return "ok";
        }
        log.warn("话单事件:" + message);

        com.alibaba.fastjson.JSONArray feeInfoList = jsonObject.getJSONArray("feeLst");
        feeInfoList.forEach(item -> {
            com.alibaba.fastjson.JSONObject feeInfo = com.alibaba.fastjson.JSONObject.parseObject(item.toString());
            String callerNum = feeInfo.getString("calleeNum"); //主叫
            String calleeNum = feeInfo.getString("fwdDstNum"); //被叫

            String icid = feeInfo.getString("icid");
            String fwdAnswerTime1 = feeInfo.getString("fwdAnswerTime");
            //应答时间:
            String fwdAnswerTime = DateUtil.addDateMinut(fwdAnswerTime1, 8);
            String callEndTime1 = feeInfo.getString("callEndTime");
            //真实的结束事件
            String callEndTime = DateUtil.addDateMinut(callEndTime1, 8);
            //携带的参数 callbackinfo
            String userData = feeInfo.getString("userData"); //携带的标记
            //通话时间:秒
            int calltime1 = DateUtil.calLastedTime(callEndTime, fwdAnswerTime);


            //userData //携带标记
//        // \"2018-05-28
//        // 21:14:59\",\"Call_bill\": 0.12,\"Call_duration\":
//        // 79,\"Call_endtime\": \"2018-05-28 21:16:18\",\"Call_id\":
//        // \"aa57b8df16ac45b580272ab266186d1a\",\"Call_starttime\": \"2018-05-28
//        // 18:57:32\",\"Callee\": \"+8618867860012\",\"Caller\":
//        // \"+8615168269848\",\"Request_time\": \"2018-05-28
//        // 21:14:47\",\"Extends\":\" \"}";
            Apiinfoes apiinfoes = ApiinfoesHelper.createApiinfoes(request, "SC线路回调单");
            apiinfoesService.insert(ApiinfoesHelper.setApiinfoes(apiinfoes, message, "ok"));
            // 1.解析返回参数（JHRESULT）
            JHresult call = new JHresult(icid, fwdAnswerTime, null, calltime1, callEndTime, userData, fwdAnswerTime, callerNum, calleeNum, callEndTime, null);
            if (call != null) {
                call.Callee = call.Callee.replace("+86", "").trim(); // 被叫
                call.Caller = call.Caller.replace("+86", "").trim(); // 主叫
                // 2. 查询该话单
                Callbackinfoes callbackinfoes = callbackinfoesService.selectByPrimaryKey(call.Call_id);
                if (callbackinfoes != null) {
                    // a.若存在此话单进行更新
                    if (call.Call_duration == 0) {
                        // a.0时长直接更新话单
                        callbackinfoes.setSysnum("JH推送话单");
                        try {
                            callbackinfoes.setCalltime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Request_time));
                            callbackinfoes.setEndtime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Request_time));
                        } catch (ParseException e) {
                            e.printStackTrace();
                            log.error(e.getMessage());
                        }

                        callbackinfoes.setFwdtime(Produce.getNowDate());
                        callbackinfoes.setMoney(new BigDecimal(0));
                        callbackinfoes.setOmoney(new BigDecimal(0));
                        callbackinfoes.setTimecount(0);
                        callbackinfoes.setStatus("未接通");
                        callbackinfoesService.updateByPrimaryKeySelective(callbackinfoes);
                        log.warn("成功更新订单");
                        System.out.println("成功更新订单");
                    } else {
                        // b.非0时长
                        float mins = (float) call.Call_duration / 60;
                        double secound = Math.ceil(mins);// 分钟数
                        // 查询该用户
                        SubscribersExample subscribersExample = new SubscribersExample();
                        subscribersExample.getOredCriteria()
                                .add(subscribersExample.createCriteria().andMobileEqualTo(call.Caller)
                                        .andParentidEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                        List<Subscribers> subs = subscribersService.selectByExample(subscribersExample);
                        Subscribers user = null;
                        // 查询该代理
                        UsersExample usersExample = new UsersExample();
                        usersExample.getOredCriteria().add(usersExample.createCriteria()
                                .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                        List<Users> users = usersService.selectByExample(usersExample);
                        Users agent = null;
                        // VOS查询该账号
                        if ((subs != null && subs.size() == 1) && (users != null && users.size() == 1)) {
                            user = subs.get(0);
                            agent = users.get(0);

                            // 查询分享者 变更前话费余额
                            BigDecimal beforeB = new BigDecimal(0);
                            //备注
                            String remark = null;
                            try {
                                // TODO 暂时配注
                                String userR = VosHelper
                                        .GetVosAccount("{accounts:['" + agent.getAgentprefix() + user.getMobile() + "']}");
                                if (userR != null) {
                                    VosModelList userR1 = GsonUtil.getObject(userR, VosModelList.class);
                                    if (userR1.retCode == 0) {
                                        beforeB = userR1.infoCustomers[0].getMoney();
                                    } else {
                                        beforeB = new BigDecimal(0);
                                        remark = "暂无记录";
                                    }
                                }
                            } catch (Exception e) {
                                beforeB = new BigDecimal(0);
                                remark = "暂无记录";
                            }
                            // 变更话费金额
                            BigDecimal changeB = new BigDecimal(0);

                            // TODO 查询费率
                            // String results = VosHelper
                            // .GetVosAccount("{accounts:['" +
                            // agent.getAgentprefix() + user.getMobile() + "']}");
                            // VosModelList v1 = GsonUtil.getObject(results,
                            // VosModelList.class);
                            // String fe = v1.infoCustomers[0].feeRateGroup;
                            // System.out.println(fe);
                            Freeroutes f = null;
                            String freeroute = agent.getFreeroute();
                            // TODO 费率组检测
                            if (freeroute.contains("随便打") || freeroute.contains("季卡") || freeroute.contains("月卡") || freeroute.contains("0.25")) {
                                f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.25), true, 60,
                                        Produce.getNowDate());
                            } else if (freeroute.contains("0.2") || freeroute.contains("年卡")) {
                                f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.2), true, 60,
                                        Produce.getNowDate());
                            } else if (freeroute.contains("0.3")) {
                                f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.3), true, 60,
                                        Produce.getNowDate());
                            } else if (freeroute.contains("高频") || freeroute.contains("乐淘通") || freeroute.contains("0.6")) {
                                f = new Freeroutes(Produce.getUUID(), "高频用户", new BigDecimal(0.6), true, 60,
                                        Produce.getNowDate());
                            } else {
                                FreeroutesExample freeroutesExample = new FreeroutesExample();
                                freeroutesExample.getOredCriteria().add(freeroutesExample.createCriteria()
                                        .andNameLike("%" + freeroute + "%").andDatastatusEqualTo(true));
                                List<Freeroutes> freeroutes = freeroutesService.selectByExample(freeroutesExample);
                                if (freeroutes != null && freeroutes.size() > 0) {
                                    f = freeroutes.get(0);
                                }
                            }

                            if (f != null) {
                                //???
                                if (f.getRatelength() != 60) {
                                    float min = (float) call.Call_duration / f.getRatelength();
                                    secound = Math.ceil(min);// 分钟数
                                }
                                // 计算费用
                                BigDecimal money = f.getFeelroute().multiply(new BigDecimal(secound)); // 费用
                                changeB = money;
                                BigDecimal fl = JHHelper.JH;
                                BigDecimal omon = fl.multiply(new BigDecimal(secound));
                                System.out.println("secound:" + secound + "money:" + money + "omon:" + omon);
                                // 进行扣费
                                if (user.getType() == 7) {
                                    if (user.getParentid().equals("687f444917634ae9ab3d20e97c24ee8e")) { //如果是南海一号进行独特的扣费逻辑
                                        int value = money.multiply(new BigDecimal("10.00")).intValue();
                                        int oldMoney = user.getShopBalance();
                                        String result = VosHelper.GetVosAccount("{accounts:['" + agent.getAgentprefix() + user.getMobile() + "']}");
                                        VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
                                        BigDecimal balance = v1.infoCustomers[0].money; // 用户余额
                                        //进行判断
                                        if (oldMoney >= value) {
                                            user.setShopBalance(oldMoney - value);
                                            subscribersService.updateByPrimaryKeySelective(user);
                                        } else {
                                            UsersExample listsExample = new UsersExample();
                                            listsExample.getOredCriteria().add(listsExample.createCriteria()
                                                    .andIdEqualTo(user.getShopid()).andDatastatusEqualTo(true));
                                            List<Users> lists = usersService.selectByExample(listsExample);
                                            Users list = null;
                                            UsersExample agents1sExample = new UsersExample();
                                            agents1sExample.getOredCriteria().add(agents1sExample.createCriteria()
                                                    .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                                            List<Users> agents1s = usersService.selectByExample(agents1sExample);
                                            Users agents1 = null;
                                            if ((lists != null && lists.size() == 1)
                                                    || (agents1s != null && agents1s.size() == 1)) {
                                                list = lists.get(0);
                                                agents1 = agents1s.get(0);
                                                VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getAgentprefix()
                                                        + callbackinfoes.getCaller() + "\",\"ownerType\":\"2\",\"money\":\"-"
                                                        + money + "\",\"memo\":\"用户通话扣费:" + money + "元\"}");
                                                VosHelper.PayVosAccount("{\"ownerName\":\"" + list.getUsername()
                                                        + "\",\"ownerType\":\"2\",\"money\":\"-" + money + "\",\"memo\":\"用户通话扣费:"
                                                        + money + "元\"}");
                                                VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getUsername()
                                                        + "j\",\"ownerType\":\"2\",\"money\":\"-" + omon + "\",\"memo\":\"用户通话扣线路费:"
                                                        + omon + "元\"}");
                                            }
                                            callbackinfoes.setMoney(money);
                                        }
                                        //正常用户扣费逻辑
                                    } else {
                                        UsersExample listsExample = new UsersExample();
                                        listsExample.getOredCriteria().add(listsExample.createCriteria()
                                                .andIdEqualTo(user.getShopid()).andDatastatusEqualTo(true));
                                        List<Users> lists = usersService.selectByExample(listsExample);
                                        Users list = null;
                                        UsersExample agents1sExample = new UsersExample();
                                        agents1sExample.getOredCriteria().add(agents1sExample.createCriteria()
                                                .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                                        List<Users> agents1s = usersService.selectByExample(agents1sExample);
                                        Users agents1 = null;
                                        if ((lists != null && lists.size() == 1)
                                                || (agents1s != null && agents1s.size() == 1)) {
                                            list = lists.get(0);
                                            agents1 = agents1s.get(0);
                                            VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getAgentprefix()
                                                    + callbackinfoes.getCaller() + "\",\"ownerType\":\"2\",\"money\":\"-"
                                                    + money + "\",\"memo\":\"用户通话扣费:" + money + "元\"}");
                                            VosHelper.PayVosAccount("{\"ownerName\":\"" + list.getUsername()
                                                    + "\",\"ownerType\":\"2\",\"money\":\"-" + money + "\",\"memo\":\"用户通话扣费:"
                                                    + money + "元\"}");
                                            VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getUsername()
                                                    + "j\",\"ownerType\":\"2\",\"money\":\"-" + omon + "\",\"memo\":\"用户通话扣线路费:"
                                                    + omon + "元\"}");
                                        }
                                        callbackinfoes.setMoney(money);
                                    }
                                } else {
                                    callbackinfoes.setMoney(new BigDecimal(0));
                                }
                                // 更新话单
                                callbackinfoes.setSysnum("JH推送话单");
                                try {
                                    callbackinfoes
                                            .setCalltime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Request_time));
                                    callbackinfoes
                                            .setEndtime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Request_time));
                                    callbackinfoes.setFwdtime(
                                            new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Call_answertime));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    log.error("话单存储报错：" + e.getMessage());
                                }

                                callbackinfoes.setOmoney(omon);
                                callbackinfoes.setTimecount(call.Call_duration);
                                callbackinfoes.setStatus("接通");
                                callbackinfoesService.updateByPrimaryKeySelective(callbackinfoes);
                                Long calltime = 0L;
                                Long endTime = 0L;
                                Long fwdTime = 0L;
                                //淘时代回调
                                if (agent.getId().equals("6892db9945474dc6bc5004a8f5b9d0f9")) {
                                    calltime = callbackinfoes.getCalltime().getTime();
                                    endTime = callbackinfoes.getEndtime().getTime();
                                    fwdTime = callbackinfoes.getFwdtime().getTime();
                                    callbackinfoes.setCalltimeStr(calltime);
                                    callbackinfoes.setEndTimeStr(endTime);
                                    callbackinfoes.setFwdTimeStr(fwdTime);
                                    String get = JSONObject.fromObject(callbackinfoes).toString();
                                    String result = null;
                                    try {
                                        result = WebHelper.PostData("http://tsd.lk99.cn/app/tel/telHang?param=" + encode(get, "utf-8") + "&sign=bGlhbmthaml0dWFuODg420", null, "application/x-www-form-urlencoded", null);
                                    } catch (UnsupportedEncodingException e) {
                                        e.printStackTrace();
                                    }
                                    System.out.println("接口返回值" + result);
                                }
                                if (agent.getId().equals("875ebeb6fe52464ca8c9c418199e774b")) {
                                    String get = JSONObject.fromObject(callbackinfoes).toString();
                                    String result = null;
                                    try {
                                        result = WebHelper.PostData("http://car-clue.ruiqinet.com/car_clue/App/call_back?param=" + encode(get, "GBK"), null, "application/x-www-form-urlencoded", null);
                                    } catch (UnsupportedEncodingException e) {
                                        e.printStackTrace();
                                    }
                                    System.out.println("接口返回值" + result);
                                }
                                //骑士卡推送
                                if (agent.getId().equals("d86d7b1fbdcb427798485dd8581625e8")) {
                                    String str = qskUtils.getCallBackURL(callbackinfoes);
                                    JSONObject jsonObject1 = JSONObject.fromObject(str);
                                    DelayPostCallWorker work = new DelayPostCallWorker(jsonObject1, null, 3);
                                    DelayOrderQueueManager manager = DelayOrderQueueManager.getInstance();
                                    manager.put(work, 0, TimeUnit.MILLISECONDS);
//                                    String appsecret = "7F499C134731050CC1E9671C2289B458";
//                                    String sign = SignUtil.getSign("utf-8", maps, appsecret);
//                                    System.out.println(sign);
                                }
                                //首享话单推送
                                if (agent.getId().equals("0f5b422825c041049c48d8baaf184bb5") || agent.getId().equals("be231a9a1edc4b549b60ab7a84a62bc4")) {
                                    callbackinfoes.setOmoney(null);
                                    String get = JSONObject.fromObject(callbackinfoes).toString();
                                    String key = "514b35da529ecf0f0ebfa76f54aa5699";
                                    String sign = MD5Util.MD5Encode(get + key, "UTF-8").toLowerCase();
                                    String param1 = "suiBianDaCallBillCallback=" + get + "&sign=" + sign;
                                    String result = null;
                                    try {
                                        String url = "http://api.daniaodianhua.com/callback/suibianda?suiBianDaCallBillCallback=" + encode(get, "utf-8") + "&sign=" + sign;
                                        DelayOrderWorker work = new DelayOrderWorker(url, null, 3);
                                        DelayOrderQueueManager manager = DelayOrderQueueManager.getInstance();
                                        manager.put(work, 3000, TimeUnit.MILLISECONDS);
                                    } catch (UnsupportedEncodingException e) {
                                        e.printStackTrace();
                                        log.error("error call" + e.getMessage());
                                    }
//                                    log.warn("callback" + callbackinfoes.getCaller() + "result:" + result);
                                }

                                try {
                                    // 话费变更记录
                                    changeRecordService.insertSelective(new ChangeRecord(user.getParentid(), user.getShopid(), user.getId(),
                                            Produce.getNowDate(), beforeB, changeB, 0, user.getEndtime(), user.getEndtime(), "拨打电话",
                                            BigDecimal.valueOf(user.getShopBalance()), BigDecimal.valueOf(0), 0,
                                            new SimpleDateFormat("yyyy-MM-dd").parse(user.getShopEnddate()),
                                            new SimpleDateFormat("yyyy-MM-dd").parse(user.getShopEnddate()), "拨打电话", remark));
                                } catch (Exception e) {
                                    logsService.insert(CommContent.TYPE_CREATE, user.getMobile() + "拨打电话余额变更记录异常", agent.getUsername(), true,
                                            IP.getIpAddr(request));
                                }

//                            netState.setErrorCode(NetState.SUCCESS_CONN);
                                log.warn("成功更新订单");
                                System.out.println("成功更新订单");
                            } else {
//                            netState.setErrorCode(NetState.NODATA);
                                log.warn("无法匹配此费率");
                                System.out.println("无法匹配此费率");
                            }
                        } else {
//                        netState.setErrorCode(NetState.NODATA);
                            log.warn("用户或者代理不存在");
                            System.out.println("用户或者代理不存在");
                        }
                    }
                } else {
//                netState.setErrorCode(NetState.NODATA);
                    log.warn("话单不存在");
                    System.out.println("话单不存在");
                }
            } else {
//            netState.setErrorCode(NetState.SYSTEM_ERROR);
                log.warn("话单返回值解析失败");
                System.out.println("话单返回值解析失败");
            }

        });

        return "ok";
    }

//    /**
//     *  @Date: 2020/5/8 11:00
//     *  @Description:
//     *
//     */
//    public static void getCallSC(com.alibaba.fastjson.JSONObject feeInfo,HttpServletRequest request ){
//        String callerNum=feeInfo.getString("calleeNum"); //主叫
//        String calleeNum=feeInfo.getString("fwdDstNum"); //被叫
//
//        String icid=feeInfo.getString("icid");
//        String fwdAnswerTime1=feeInfo.getString("fwdAnswerTime");
//        //应答时间:
//        String fwdAnswerTime=DateUtil.addDateMinut(fwdAnswerTime1,8);
//        String callEndTime1=feeInfo.getString("callEndTime");
//        //真实的结束事件
//        String callEndTime=DateUtil.addDateMinut(callEndTime1,8);
//        //携带的参数 callbackinfo
//        String userData=feeInfo.getString("userData"); //携带的标记
//        //通话时间:秒
//        int calltime1=DateUtil.calLastedTime(callEndTime,fwdAnswerTime);
//
//
//
//        //userData //携带标记
////        // \"2018-05-28
////        // 21:14:59\",\"Call_bill\": 0.12,\"Call_duration\":
////        // 79,\"Call_endtime\": \"2018-05-28 21:16:18\",\"Call_id\":
////        // \"aa57b8df16ac45b580272ab266186d1a\",\"Call_starttime\": \"2018-05-28
////        // 18:57:32\",\"Callee\": \"+8618867860012\",\"Caller\":
////        // \"+8615168269848\",\"Request_time\": \"2018-05-28
////        // 21:14:47\",\"Extends\":\" \"}";
//        Apiinfoes apiinfoes = ApiinfoesHelper.createApiinfoes(request, "SC线路回调单");
//        apiinfoesService.insert(ApiinfoesHelper.setApiinfoes(apiinfoes, message, "ok"));
//        // 1.解析返回参数（JHRESULT）
//        JHresult call = new JHresult(icid, fwdAnswerTime,null,calltime1, callEndTime,userData, fwdAnswerTime, callerNum, calleeNum, callEndTime, null);
//        if (call != null) {
//            call.Callee = call.Callee.replace("+86", "").trim(); // 被叫
//            call.Caller = call.Caller.replace("+86", "").trim(); // 主叫
//            // 2. 查询该话单
//            Callbackinfoes callbackinfoes = callbackinfoesService.selectByPrimaryKey(call.Call_id);
//            if (callbackinfoes != null) {
//                // a.若存在此话单进行更新
//                if (call.Call_duration == 0) {
//                    // a.0时长直接更新话单
//                    callbackinfoes.setSysnum("JH推送话单");
//                    callbackinfoes.setCalltime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Request_time));
//                    callbackinfoes.setEndtime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Request_time));
//                    callbackinfoes.setFwdtime(Produce.getNowDate());
//                    callbackinfoes.setMoney(new BigDecimal(0));
//                    callbackinfoes.setOmoney(new BigDecimal(0));
//                    callbackinfoes.setTimecount(0);
//                    callbackinfoes.setStatus("未接通");
//                    callbackinfoesService.updateByPrimaryKeySelective(callbackinfoes);
//                    log.warn("成功更新订单");
//                    System.out.println("成功更新订单");
//                } else {
//                    // b.非0时长
//                    float mins = (float) call.Call_duration / 60;
//                    double secound = Math.ceil(mins);// 分钟数
//                    // 查询该用户
//                    SubscribersExample subscribersExample = new SubscribersExample();
//                    subscribersExample.getOredCriteria()
//                            .add(subscribersExample.createCriteria().andMobileEqualTo(call.Caller)
//                                    .andParentidEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
//                    List<Subscribers> subs = subscribersService.selectByExample(subscribersExample);
//                    Subscribers user = null;
//                    // 查询该代理
//                    UsersExample usersExample = new UsersExample();
//                    usersExample.getOredCriteria().add(usersExample.createCriteria()
//                            .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
//                    List<Users> users = usersService.selectByExample(usersExample);
//                    Users agent = null;
//                    // VOS查询该账号
//                    if ((subs != null && subs.size() == 1) && (users != null && users.size() == 1)) {
//                        user = subs.get(0);
//                        agent = users.get(0);
//
//                        // 查询分享者 变更前话费余额
//                        BigDecimal beforeB = new BigDecimal(0);
//                        //备注
//                        String remark = null;
//                        try {
//                            // TODO 暂时配注
//                            String userR = VosHelper
//                                    .GetVosAccount("{accounts:['" + agent.getAgentprefix() + user.getMobile() + "']}");
//                            if (userR != null) {
//                                VosModelList userR1 = GsonUtil.getObject(userR, VosModelList.class);
//                                if (userR1.retCode == 0) {
//                                    beforeB = userR1.infoCustomers[0].getMoney();
//                                } else {
//                                    beforeB = new BigDecimal(0);
//                                    remark = "暂无记录";
//                                }
//                            }
//                        } catch (Exception e) {
//                            beforeB = new BigDecimal(0);
//                            remark = "暂无记录";
//                        }
//                        // 变更话费金额
//                        BigDecimal changeB = new BigDecimal(0);
//
//                        // TODO 查询费率
//                        // String results = VosHelper
//                        // .GetVosAccount("{accounts:['" +
//                        // agent.getAgentprefix() + user.getMobile() + "']}");
//                        // VosModelList v1 = GsonUtil.getObject(results,
//                        // VosModelList.class);
//                        // String fe = v1.infoCustomers[0].feeRateGroup;
//                        // System.out.println(fe);
//                        Freeroutes f = null;
//                        String freeroute = agent.getFreeroute();
//                        // TODO 费率组检测
//                        if (freeroute.contains("随便打") || freeroute.contains("季卡") || freeroute.contains("月卡") || freeroute.contains("0.25")) {
//                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.25), true, 60,
//                                    Produce.getNowDate());
//                        } else if (freeroute.contains("0.2") || freeroute.contains("年卡")) {
//                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.2), true, 60,
//                                    Produce.getNowDate());
//                        } else if (freeroute.contains("0.3")) {
//                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.3), true, 60,
//                                    Produce.getNowDate());
//                        } else if (freeroute.contains("高频") || freeroute.contains("乐淘通") || freeroute.contains("0.6")) {
//                            f = new Freeroutes(Produce.getUUID(), "高频用户", new BigDecimal(0.6), true, 60,
//                                    Produce.getNowDate());
//                        } else {
//                            FreeroutesExample freeroutesExample = new FreeroutesExample();
//                            freeroutesExample.getOredCriteria().add(freeroutesExample.createCriteria()
//                                    .andNameLike("%" + freeroute + "%").andDatastatusEqualTo(true));
//                            List<Freeroutes> freeroutes = freeroutesService.selectByExample(freeroutesExample);
//                            if (freeroutes != null && freeroutes.size() > 0) {
//                                f = freeroutes.get(0);
//                            }
//                        }
//
//                        if (f != null) {
//                            //???
//                            if (f.getRatelength() != 60) {
//                                float min = (float) call.Call_duration / f.getRatelength();
//                                secound = Math.ceil(min);// 分钟数
//                            }
//                            // 计算费用
//                            BigDecimal money = f.getFeelroute().multiply(new BigDecimal(secound)); // 费用
//                            changeB = money;
//                            BigDecimal fl = JHHelper.JH;
//                            BigDecimal omon = fl.multiply(new BigDecimal(secound));
//                            System.out.println("secound:" + secound + "money:" + money + "omon:" + omon);
//                            // 进行扣费
//                            if (user.getType() == 7) {
//                                if (user.getParentid().equals("687f444917634ae9ab3d20e97c24ee8e")) { //如果是南海一号进行独特的扣费逻辑
//                                    int value = money.multiply(new BigDecimal("10.00")).intValue();
//                                    int oldMoney = user.getShopBalance();
//                                    String result = VosHelper.GetVosAccount("{accounts:['" + agent.getAgentprefix() + user.getMobile() + "']}");
//                                    VosModelList v1 = GsonUtil.getObject(result, VosModelList.class);
//                                    BigDecimal balance = v1.infoCustomers[0].money; // 用户余额
//                                    //进行判断
//                                    if (oldMoney >= value) {
//                                        user.setShopBalance(oldMoney - value);
//                                        subscribersService.updateByPrimaryKeySelective(user);
//                                    } else {
//                                        UsersExample listsExample = new UsersExample();
//                                        listsExample.getOredCriteria().add(listsExample.createCriteria()
//                                                .andIdEqualTo(user.getShopid()).andDatastatusEqualTo(true));
//                                        List<Users> lists = usersService.selectByExample(listsExample);
//                                        Users list = null;
//                                        UsersExample agents1sExample = new UsersExample();
//                                        agents1sExample.getOredCriteria().add(agents1sExample.createCriteria()
//                                                .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
//                                        List<Users> agents1s = usersService.selectByExample(agents1sExample);
//                                        Users agents1 = null;
//                                        if ((lists != null && lists.size() == 1)
//                                                || (agents1s != null && agents1s.size() == 1)) {
//                                            list = lists.get(0);
//                                            agents1 = agents1s.get(0);
//                                            VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getAgentprefix()
//                                                    + callbackinfoes.getCaller() + "\",\"ownerType\":\"2\",\"money\":\"-"
//                                                    + money + "\",\"memo\":\"用户通话扣费:" + money + "元\"}");
//                                            VosHelper.PayVosAccount("{\"ownerName\":\"" + list.getUsername()
//                                                    + "\",\"ownerType\":\"2\",\"money\":\"-" + money + "\",\"memo\":\"用户通话扣费:"
//                                                    + money + "元\"}");
//                                            VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getUsername()
//                                                    + "j\",\"ownerType\":\"2\",\"money\":\"-" + omon + "\",\"memo\":\"用户通话扣线路费:"
//                                                    + omon + "元\"}");
//                                        }
//                                        callbackinfoes.setMoney(money);
//                                    }
//                                    //正常用户扣费逻辑
//                                } else {
//                                    UsersExample listsExample = new UsersExample();
//                                    listsExample.getOredCriteria().add(listsExample.createCriteria()
//                                            .andIdEqualTo(user.getShopid()).andDatastatusEqualTo(true));
//                                    List<Users> lists = usersService.selectByExample(listsExample);
//                                    Users list = null;
//                                    UsersExample agents1sExample = new UsersExample();
//                                    agents1sExample.getOredCriteria().add(agents1sExample.createCriteria()
//                                            .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
//                                    List<Users> agents1s = usersService.selectByExample(agents1sExample);
//                                    Users agents1 = null;
//                                    if ((lists != null && lists.size() == 1)
//                                            || (agents1s != null && agents1s.size() == 1)) {
//                                        list = lists.get(0);
//                                        agents1 = agents1s.get(0);
//                                        VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getAgentprefix()
//                                                + callbackinfoes.getCaller() + "\",\"ownerType\":\"2\",\"money\":\"-"
//                                                + money + "\",\"memo\":\"用户通话扣费:" + money + "元\"}");
//                                        VosHelper.PayVosAccount("{\"ownerName\":\"" + list.getUsername()
//                                                + "\",\"ownerType\":\"2\",\"money\":\"-" + money + "\",\"memo\":\"用户通话扣费:"
//                                                + money + "元\"}");
//                                        VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getUsername()
//                                                + "j\",\"ownerType\":\"2\",\"money\":\"-" + omon + "\",\"memo\":\"用户通话扣线路费:"
//                                                + omon + "元\"}");
//                                    }
//                                    callbackinfoes.setMoney(money);
//                                }
//                            } else {
//                                callbackinfoes.setMoney(new BigDecimal(0));
//                            }
//                            // 更新话单
//                            callbackinfoes.setSysnum("JH推送话单");
//                            callbackinfoes
//                                    .setCalltime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Request_time));
//                            callbackinfoes
//                                    .setEndtime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Request_time));
//                            callbackinfoes.setFwdtime(
//                                    new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(call.Call_answertime));
//                            callbackinfoes.setOmoney(omon);
//                            callbackinfoes.setTimecount(call.Call_duration);
//                            callbackinfoes.setStatus("接通");
//                            callbackinfoesService.updateByPrimaryKeySelective(callbackinfoes);
//                            Long calltime = 0L;
//                            Long endTime = 0L;
//                            Long fwdTime = 0L;
//                            //淘时代回调
//                            if (agent.getId().equals("6892db9945474dc6bc5004a8f5b9d0f9")) {
//                                calltime = callbackinfoes.getCalltime().getTime();
//                                endTime = callbackinfoes.getEndtime().getTime();
//                                fwdTime = callbackinfoes.getFwdtime().getTime();
//                                callbackinfoes.setCalltimeStr(calltime);
//                                callbackinfoes.setEndTimeStr(endTime);
//                                callbackinfoes.setFwdTimeStr(fwdTime);
//                                String get = JSONObject.fromObject(callbackinfoes).toString();
//                                String result = WebHelper.PostData("http://tsd.lk99.cn/app/tel/telHang?param=" + encode(get, "utf-8") + "&sign=bGlhbmthaml0dWFuODg420", null, "application/x-www-form-urlencoded", null);
//                                System.out.println("接口返回值" + result);
//                            }
//                            if (agent.getId().equals("875ebeb6fe52464ca8c9c418199e774b")) {
//                                String get = JSONObject.fromObject(callbackinfoes).toString();
//                                String result = WebHelper.PostData("http://car-clue.ruiqinet.com/car_clue/App/call_back?param=" + encode(get, "GBK"), null, "application/x-www-form-urlencoded", null);
//                                System.out.println("接口返回值" + result);
//                            }
//                            //首享话单推送
//                            if (agent.getId().equals("0f5b422825c041049c48d8baaf184bb5")) {
//                                callbackinfoes.setOmoney(null);
//                                String get = JSONObject.fromObject(callbackinfoes).toString();
//                                String key="514b35da529ecf0f0ebfa76f54aa5699";
//                                String sign= MD5Util.MD5Encode(get+key, "UTF-8").toLowerCase();
//                                String param1="suiBianDaCallBillCallback="+get+"&sign="+sign;
//                                String result = WebHelper.PostData("http://api.daniaodianhua.com/callback/suibianda?suiBianDaCallBillCallback="+encode(get, "utf-8")+"&sign="+sign, null, "application/x-www-from-urlencoded", null);
//                                log.warn("callback"+callbackinfoes.getCaller()+"result:"+result);
//                            }
//
//                            try {
//                                // 话费变更记录
//                                changeRecordService.insertSelective(new ChangeRecord(user.getParentid(), user.getShopid(), user.getId(),
//                                        Produce.getNowDate(), beforeB, changeB, 0, user.getEndtime(), user.getEndtime(), "拨打电话",
//                                        BigDecimal.valueOf(user.getShopBalance()), BigDecimal.valueOf(0), 0,
//                                        new SimpleDateFormat("yyyy-MM-dd").parse(user.getShopEnddate()),
//                                        new SimpleDateFormat("yyyy-MM-dd").parse(user.getShopEnddate()), "拨打电话", remark));
//                            } catch (Exception e) {
//                                logsService.insert(CommContent.TYPE_CREATE, user.getMobile() + "拨打电话余额变更记录异常", agent.getUsername(), true,
//                                        IP.getIpAddr(request));
//                            }
//
////                            netState.setErrorCode(NetState.SUCCESS_CONN);
//                            log.warn("成功更新订单");
//                            System.out.println("成功更新订单");
//                        } else {
////                            netState.setErrorCode(NetState.NODATA);
//                            log.warn("无法匹配此费率");
//                            System.out.println("无法匹配此费率");
//                        }
//                    } else {
////                        netState.setErrorCode(NetState.NODATA);
//                        log.warn("用户或者代理不存在");
//                        System.out.println("用户或者代理不存在");
//                    }
//                }
//            } else {
////                netState.setErrorCode(NetState.NODATA);
//                log.warn("话单不存在");
//                System.out.println("话单不存在");
//            }
//        } else {
////            netState.setErrorCode(NetState.SYSTEM_ERROR);
//            log.warn("话单返回值解析失败");
//            System.out.println("话单返回值解析失败");
//        }
//    }
//

    /**
     * Call话单推送
     *
     * @param request
     */
    @RequestMapping(value = "/callNotify", method = {RequestMethod.POST, RequestMethod.GET})
    public @ResponseBody
    NetState callNotify(HttpServletRequest request) {
        NetState netState = new NetState();
        Apiinfoes apiinfoes = ApiinfoesHelper.createApiinfoes(request, "Call线路话单");
        // 1.解析返回参数
        String orderid = request.getParameter("orderid"); // 订单号
        String fee_time = request.getParameter("fee_time"); // 计费时间
        String hold_time = request.getParameter("hold_time"); // 通话时间
        String start_time = request.getParameter("start_time"); // 开始时间
        String end_time = request.getParameter("end_time"); // 结束时间
        if (orderid != null && !orderid.isEmpty()) {
            // 2. 查询该话单
            Callbackinfoes callbackinfoes = callbackinfoesService.selectByPrimaryKey(orderid);
            if (callbackinfoes != null) {
                String caller = callbackinfoes.getCaller().replace("+86", "").trim(); // 主叫
                String callee = callbackinfoes.getCalle164().replace("+86", "").trim(); // 被叫
                // a.若存在此话单进行更新
                if (hold_time == null || hold_time.isEmpty() || hold_time.equals("0")) {
                    // a.0时长直接更新话单
                    callbackinfoes.setSysnum("Call推送话单");
                    callbackinfoes.setCalltime(new Date(new Long(start_time + "000")));
                    callbackinfoes.setEndtime(new Date(new Long(end_time + "000")));
                    callbackinfoes.setFwdtime(Produce.getNowDate());
                    callbackinfoes.setMoney(new BigDecimal(0));
                    callbackinfoes.setOmoney(new BigDecimal(0));
                    callbackinfoes.setTimecount(0);
                    callbackinfoes.setStatus("未接通");
                    callbackinfoesService.updateByPrimaryKeySelective(callbackinfoes);
                    netState.setErrorCode(NetState.SUCCESS_CONN);
                    netState.setData("成功更新订单");
                    System.out.println("成功更新订单");
                } else {
                    // b.非0时长
                    float mins = Float.parseFloat(hold_time) / 60;
                    double secound = Math.ceil(mins);// 分钟数
                    // 查询该用户
                    SubscribersExample subscribersExample = new SubscribersExample();
                    subscribersExample.getOredCriteria()
                            .add(subscribersExample.createCriteria().andMobileEqualTo(caller)
                                    .andParentidEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                    List<Subscribers> subs = subscribersService.selectByExample(subscribersExample);
                    Subscribers user = null;
                    // 查询该代理
                    UsersExample usersExample = new UsersExample();
                    usersExample.getOredCriteria().add(usersExample.createCriteria()
                            .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                    List<Users> users = usersService.selectByExample(usersExample);
                    Users agent = null;
                    // VOS查询该账号
                    if ((subs != null && subs.size() == 1) && (users != null && users.size() == 1)) {
                        user = subs.get(0);
                        agent = users.get(0);

                        // 查询分享者 变更前话费余额
                        BigDecimal beforeB = new BigDecimal(0);
                        //备注
                        String remark = null;
                        try {
                            // TODO 暂时配注
                            String userR = VosHelper
                                    .GetVosAccount("{accounts:['" + agent.getAgentprefix() + user.getMobile() + "']}");
                            if (userR != null) {
                                VosModelList userR1 = GsonUtil.getObject(userR, VosModelList.class);
                                if (userR1.retCode == 0) {
                                    beforeB = userR1.infoCustomers[0].getMoney();
                                } else {
                                    beforeB = new BigDecimal(0);
                                    remark = "暂无记录";
                                }
                            }
                        } catch (Exception e) {
                            beforeB = new BigDecimal(0);
                            remark = "暂无记录";
                        }
                        // 变更话费金额
                        BigDecimal changeB = new BigDecimal(0);

                        // TODO 查询费率
                        // String results = VosHelper
                        // .GetVosAccount("{accounts:['" +
                        // agent.getAgentprefix() + user.getMobile() + "']}");
                        // VosModelList v1 = GsonUtil.getObject(results,
                        // VosModelList.class);
                        // String fe = v1.infoCustomers[0].feeRateGroup;
                        // System.out.println(fe);
                        Freeroutes f = null;
                        String freeroute = agent.getFreeroute();
                        // TODO 费率组检测
                        if (freeroute.contains("随便打") || freeroute.contains("季卡") || freeroute.contains("月卡") || freeroute.contains("0.25")) {
                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.25), true, 60,
                                    Produce.getNowDate());
                        } else if (freeroute.contains("0.2") || freeroute.contains("年卡")) {
                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.2), true, 60,
                                    Produce.getNowDate());
                        } else if (freeroute.contains("0.3")) {
                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.3), true, 60,
                                    Produce.getNowDate());
                        } else if (freeroute.contains("高频") || freeroute.contains("乐淘通") || freeroute.contains("0.6")) {
                            f = new Freeroutes(Produce.getUUID(), "高频用户", new BigDecimal(0.6), true, 60,
                                    Produce.getNowDate());
                        } else {
                            FreeroutesExample freeroutesExample = new FreeroutesExample();
                            freeroutesExample.getOredCriteria().add(freeroutesExample.createCriteria()
                                    .andNameLike("%" + freeroute + "%").andDatastatusEqualTo(true));
                            List<Freeroutes> freeroutes = freeroutesService.selectByExample(freeroutesExample);
                            if (freeroutes != null && freeroutes.size() > 0) {
                                f = freeroutes.get(0);
                            }
                        }

                        if (f != null) {
                            if (f.getRatelength() != 60) {
                                float min = Float.parseFloat(hold_time) / f.getRatelength();
                                secound = Math.ceil(min);// 分钟数
                            }
                            // 计算费用
                            BigDecimal money = f.getFeelroute().multiply(new BigDecimal(secound)); // 费用
                            changeB = money;
                            BigDecimal fl = JHHelper.JH;
                            BigDecimal omon = fl.multiply(new BigDecimal(secound));
                            System.out.println("secound:" + secound + "money:" + money + "omon:" + omon);
                            // 进行扣费
                            if (user.getType() == 7) {
                                UsersExample listsExample = new UsersExample();
                                listsExample.getOredCriteria().add(listsExample.createCriteria()
                                        .andIdEqualTo(user.getShopid()).andDatastatusEqualTo(true));
                                List<Users> lists = usersService.selectByExample(listsExample);
                                Users list = null;
                                UsersExample agents1sExample = new UsersExample();
                                agents1sExample.getOredCriteria().add(agents1sExample.createCriteria()
                                        .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                                List<Users> agents1s = usersService.selectByExample(agents1sExample);
                                Users agents1 = null;
                                if ((lists != null && lists.size() == 1)
                                        || (agents1s != null && agents1s.size() == 1)) {
                                    list = lists.get(0);
                                    agents1 = agents1s.get(0);
                                    VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getAgentprefix()
                                            + callbackinfoes.getCaller() + "\",\"ownerType\":\"2\",\"money\":\"-"
                                            + money + "\",\"memo\":\"用户通话扣费:" + money + "元\"}");
                                    VosHelper.PayVosAccount("{\"ownerName\":\"" + list.getUsername()
                                            + "\",\"ownerType\":\"2\",\"money\":\"-" + money + "\",\"memo\":\"用户通话扣费:"
                                            + money + "元\"}");
                                    VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getUsername()
                                            + "j\",\"ownerType\":\"2\",\"money\":\"-" + omon + "\",\"memo\":\"用户通话扣线路费:"
                                            + omon + "元\"}");
                                }
                                callbackinfoes.setMoney(money);
                            } else {
                                callbackinfoes.setMoney(new BigDecimal(0));
                            }
                            // 更新话单
                            callbackinfoes.setSysnum("Call推送话单");
                            callbackinfoes.setCalltime(new Date(new Long(start_time + "000")));
                            callbackinfoes.setEndtime(new Date(new Long(end_time + "000")));
                            callbackinfoes.setFwdtime(new Date(new Long(start_time + "000")));
                            callbackinfoes.setOmoney(omon);
                            callbackinfoes.setTimecount(Integer.parseInt(hold_time));
                            callbackinfoes.setStatus("接通");
                            callbackinfoesService.updateByPrimaryKeySelective(callbackinfoes);

//                            if (agent.getId().equals("875ebeb6fe52464ca8c9c418199e774b")){
//                                WebHelper.PostData(" http://laofengge.ruiqinet.com/laofengge/login/test", "param=" + JSONObject.fromObject(callbackinfoes), null, null);
//                            }

                            try {
                                // 话费变更记录
                                changeRecordService.insertSelective(new ChangeRecord(user.getParentid(), user.getShopid(), user.getId(),
                                        Produce.getNowDate(), beforeB, changeB, 0, user.getEndtime(), user.getEndtime(), "拨打电话",
                                        BigDecimal.valueOf(user.getShopBalance()), BigDecimal.valueOf(0), 0,
                                        new SimpleDateFormat("yyyy-MM-dd").parse(user.getShopEnddate()),
                                        new SimpleDateFormat("yyyy-MM-dd").parse(user.getShopEnddate()), "拨打电话", remark));
                            } catch (Exception e) {
                                logsService.insert(CommContent.TYPE_CREATE, user.getMobile() + "拨打电话余额变更记录异常", agent.getUsername(), true,
                                        IP.getIpAddr(request));
                            }

                            netState.setErrorCode(NetState.SUCCESS_CONN);
                            netState.setData("成功更新订单");
                            System.out.println("成功更新订单");
                        } else {
                            netState.setErrorCode(NetState.NODATA);
                            netState.setData("无法匹配此费率");
                            System.out.println("无法匹配此费率");
                        }
                    } else {
                        netState.setErrorCode(NetState.NODATA);
                        netState.setData("用户或者代理不存在");
                        System.out.println("用户或者代理不存在");
                    }
                }
            } else {
                netState.setErrorCode(NetState.NODATA);
                netState.setData("话单不存在");
                System.out.println("话单不存在");
            }
        } else {
            netState.setErrorCode(NetState.SYSTEM_ERROR);
            netState.setData("话单返回值解析失败");
            System.out.println("话单返回值解析失败");
        }
        apiinfoesService.insert(ApiinfoesHelper.setApiinfoes(apiinfoes, orderid, GsonUtil.createJsonString(netState)));
        return netState;
    }

    /**
     * 双透话单推送
     *
     * @param request
     */
    @RequestMapping(value = "/stNotify", method = {RequestMethod.POST, RequestMethod.GET})
    public @ResponseBody
    NetState stNotify(HttpServletRequest request) throws Exception {
        NetState netState = new NetState();
        Apiinfoes apiinfoes = ApiinfoesHelper.createApiinfoes(request, "双透线路话单");
        // 1.解析返回参数
        String orderid = request.getParameter("orderid"); // 订单号
        String fee_time = request.getParameter("fee_time"); // 计费时间
        String hold_time = request.getParameter("hold_time"); // 通话时间
        String start_time = request.getParameter("start"); // 开始时间
        String end_time = request.getParameter("end"); // 结束时间
        if (orderid != null && !orderid.isEmpty()) {
            // 2. 查询该话单
            Callbackinfoes callbackinfoes = callbackinfoesService.selectByPrimaryKey(orderid);
            if (callbackinfoes != null) {
                Integer nowTime = Integer.parseInt(String.valueOf((Produce.getNowDate().getTime() / 1000)));
                Integer callTime = Integer.parseInt(String.valueOf((callbackinfoes.getCalltime().getTime() / 1000)));
                System.out.println("回调进入时间" + (nowTime - callTime));
                if (nowTime - callTime < 10) {
                    callBack(request, callbackinfoes.getCalle164(), callbackinfoes.getCaller(), callbackinfoes.getParentid(),
                            callbackinfoes.getCaller(), false, null, null, null, null);
                }

                String caller = callbackinfoes.getCaller().replace("+86", "").trim(); // 主叫
                String callee = callbackinfoes.getCalle164().replace("+86", "").trim(); // 被叫
                // a.若存在此话单进行更新
                if (hold_time == null || hold_time.isEmpty() || hold_time.equals("0")) {
                    // a.0时长直接更新话单
                    callbackinfoes.setSysnum("ST推送话单");
                    callbackinfoes.setCalltime(new Date(new Long(start_time + "000")));
                    callbackinfoes.setEndtime(new Date(new Long(end_time + "000")));
                    callbackinfoes.setFwdtime(Produce.getNowDate());
                    callbackinfoes.setMoney(new BigDecimal(0));
                    callbackinfoes.setOmoney(new BigDecimal(0));
                    callbackinfoes.setTimecount(0);
                    callbackinfoes.setStatus("未接通");
                    callbackinfoesService.updateByPrimaryKeySelective(callbackinfoes);
                    netState.setErrorCode(NetState.SUCCESS_CONN);
                    netState.setData("成功更新订单");
                    System.out.println("成功更新订单");
                } else {
                    // b.非0时长
                    float mins = Float.parseFloat(hold_time) / 60;
                    double secound = Math.ceil(mins);// 分钟数
                    // 查询该用户
                    SubscribersExample subscribersExample = new SubscribersExample();
                    subscribersExample.getOredCriteria()
                            .add(subscribersExample.createCriteria().andMobileEqualTo(caller)
                                    .andParentidEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                    List<Subscribers> subs = subscribersService.selectByExample(subscribersExample);
                    Subscribers user = null;
                    // 查询该代理
                    UsersExample usersExample = new UsersExample();
                    usersExample.getOredCriteria().add(usersExample.createCriteria()
                            .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                    List<Users> users = usersService.selectByExample(usersExample);
                    Users agent = null;
                    // VOS查询该账号
                    if ((subs != null && subs.size() == 1) && (users != null && users.size() == 1)) {
                        user = subs.get(0);
                        agent = users.get(0);

                        // 查询分享者 变更前话费余额
                        BigDecimal beforeB = new BigDecimal(0);
                        //备注
                        String remark = null;
                        try {
                            // TODO 暂时配注
                            String userR = VosHelper
                                    .GetVosAccount("{accounts:['" + agent.getAgentprefix() + user.getMobile() + "']}");
                            if (userR != null) {
                                VosModelList userR1 = GsonUtil.getObject(userR, VosModelList.class);
                                if (userR1.retCode == 0) {
                                    beforeB = userR1.infoCustomers[0].getMoney();
                                } else {
                                    beforeB = new BigDecimal(0);
                                    remark = "暂无记录";
                                }
                            }
                        } catch (Exception e) {
                            beforeB = new BigDecimal(0);
                            remark = "暂无记录";
                        }
                        // 变更话费金额
                        BigDecimal changeB = new BigDecimal(0);

                        // TODO 查询费率
                        // String results = VosHelper
                        // .GetVosAccount("{accounts:['" +
                        // agent.getAgentprefix() + user.getMobile() + "']}");
                        // VosModelList v1 = GsonUtil.getObject(results,
                        // VosModelList.class);
                        // String fe = v1.infoCustomers[0].feeRateGroup;
                        // System.out.println(fe);
                        Freeroutes f = null;
                        String freeroute = agent.getFreeroute();
                        // TODO 费率组检测
                        if (freeroute.contains("随便打") || freeroute.contains("季卡") || freeroute.contains("月卡") || freeroute.contains("0.25")) {
                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.25), true, 60,
                                    Produce.getNowDate());
                        } else if (freeroute.contains("0.2") || freeroute.contains("年卡")) {
                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.2), true, 60,
                                    Produce.getNowDate());
                        } else if (freeroute.contains("0.3")) {
                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.3), true, 60,
                                    Produce.getNowDate());
                        } else if (freeroute.contains("高频") || freeroute.contains("乐淘通") || freeroute.contains("0.6")) {
                            f = new Freeroutes(Produce.getUUID(), "高频用户", new BigDecimal(0.6), true, 60,
                                    Produce.getNowDate());
                        } else {
                            FreeroutesExample freeroutesExample = new FreeroutesExample();
                            freeroutesExample.getOredCriteria().add(freeroutesExample.createCriteria()
                                    .andNameLike("%" + freeroute + "%").andDatastatusEqualTo(true));
                            List<Freeroutes> freeroutes = freeroutesService.selectByExample(freeroutesExample);
                            if (freeroutes != null && freeroutes.size() > 0) {
                                f = freeroutes.get(0);
                            }
                        }

                        if (f != null) {
                            if (f.getRatelength() != 60) {
                                float min = Float.parseFloat(hold_time) / f.getRatelength();
                                secound = Math.ceil(min);// 分钟数
                            }
                            // 计算费用
                            BigDecimal money = f.getFeelroute().multiply(new BigDecimal(secound)); // 费用
                            changeB = money;
                            BigDecimal fl = JHHelper.JH;
                            BigDecimal omon = fl.multiply(new BigDecimal(secound));
                            System.out.println("secound:" + secound + "money:" + money + "omon:" + omon);
                            // 进行扣费
                            if (user.getType() == 7) {
                                UsersExample listsExample = new UsersExample();
                                listsExample.getOredCriteria().add(listsExample.createCriteria()
                                        .andIdEqualTo(user.getShopid()).andDatastatusEqualTo(true));
                                List<Users> lists = usersService.selectByExample(listsExample);
                                Users list = null;
                                UsersExample agents1sExample = new UsersExample();
                                agents1sExample.getOredCriteria().add(agents1sExample.createCriteria()
                                        .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                                List<Users> agents1s = usersService.selectByExample(agents1sExample);
                                Users agents1 = null;
                                if ((lists != null && lists.size() == 1)
                                        || (agents1s != null && agents1s.size() == 1)) {
                                    list = lists.get(0);
                                    agents1 = agents1s.get(0);
                                    VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getAgentprefix()
                                            + callbackinfoes.getCaller() + "\",\"ownerType\":\"2\",\"money\":\"-"
                                            + money + "\",\"memo\":\"用户通话扣费:" + money + "元\"}");
                                    VosHelper.PayVosAccount("{\"ownerName\":\"" + list.getUsername()
                                            + "\",\"ownerType\":\"2\",\"money\":\"-" + money + "\",\"memo\":\"用户通话扣费:"
                                            + money + "元\"}");
                                    VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getUsername()
                                            + "j\",\"ownerType\":\"2\",\"money\":\"-" + omon + "\",\"memo\":\"用户通话扣线路费:"
                                            + omon + "元\"}");
                                }
                                callbackinfoes.setMoney(money);
                            } else {
                                callbackinfoes.setMoney(new BigDecimal(0));
                            }
                            // 更新话单
                            callbackinfoes.setSysnum("ST推送话单");
                            callbackinfoes.setCalltime(new Date(new Long(start_time + "000")));
                            callbackinfoes.setEndtime(new Date(new Long(end_time + "000")));
                            callbackinfoes.setFwdtime(new Date(new Long(start_time + "000")));
                            callbackinfoes.setOmoney(omon);
                            callbackinfoes.setTimecount(Integer.parseInt(hold_time));
                            callbackinfoes.setStatus("接通");
                            callbackinfoesService.updateByPrimaryKeySelective(callbackinfoes);

//                            if (agent.getId().equals("875ebeb6fe52464ca8c9c418199e774b")){
//                                WebHelper.PostData(" http://laofengge.ruiqinet.com/laofengge/login/test", "param=" + JSONObject.fromObject(callbackinfoes), null, null);
//                            }

                            try {
                                // 话费变更记录
                                changeRecordService.insertSelective(new ChangeRecord(user.getParentid(), user.getShopid(), user.getId(),
                                        Produce.getNowDate(), beforeB, changeB, 0, user.getEndtime(), user.getEndtime(), "拨打电话",
                                        BigDecimal.valueOf(user.getShopBalance()), BigDecimal.valueOf(0), 0,
                                        new SimpleDateFormat("yyyy-MM-dd").parse(user.getShopEnddate()),
                                        new SimpleDateFormat("yyyy-MM-dd").parse(user.getShopEnddate()), "拨打电话", remark));
                            } catch (Exception e) {
                                logsService.insert(CommContent.TYPE_CREATE, user.getMobile() + "拨打电话余额变更记录异常", agent.getUsername(), true,
                                        IP.getIpAddr(request));
                            }

                            netState.setErrorCode(NetState.SUCCESS_CONN);
                            netState.setData("成功更新订单");
                            System.out.println("成功更新订单");
                        } else {
                            netState.setErrorCode(NetState.NODATA);
                            netState.setData("无法匹配此费率");
                            System.out.println("无法匹配此费率");
                        }
                    } else {
                        netState.setErrorCode(NetState.NODATA);
                        netState.setData("用户或者代理不存在");
                        System.out.println("用户或者代理不存在");
                    }
                }
            } else {
                netState.setErrorCode(NetState.NODATA);
                netState.setData("话单不存在");
                System.out.println("话单不存在");
            }
        } else {
            netState.setErrorCode(NetState.SYSTEM_ERROR);
            netState.setData("话单返回值解析失败");
            System.out.println("话单返回值解析失败");
        }
        apiinfoesService.insert(ApiinfoesHelper.setApiinfoes(apiinfoes, orderid, GsonUtil.createJsonString(netState)));
        return netState;
    }

    /**
     * CP话单推送
     *
     * @param request
     */
    @RequestMapping(value = "/cpNotify", method = {RequestMethod.POST, RequestMethod.GET})
    public @ResponseBody
    NetState cpNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        NetState netState = new NetState();
        Apiinfoes apiinfoes = ApiinfoesHelper.createApiinfoes(request, "CP线路话单");
        // 1.解析返回参数
        String orderid = request.getParameter("orderid"); // 订单号
        String fee_time = request.getParameter("fee_time"); // 计费时间
        String hold_time = request.getParameter("hold_time"); // 通话时间
        String start_time = request.getParameter("start"); // 开始时间
        String end_time = request.getParameter("end"); // 结束时间

        if (orderid != null && !orderid.isEmpty()) {
            // 2. 查询该话单
            Callbackinfoes callbackinfoes = callbackinfoesService.selectByPrimaryKey(orderid);

            if (callbackinfoes != null && callbackinfoes.getStatus().equals("接通")) {
                netState.setErrorCode(NetState.FEAILED);
                netState.setData("订单重复更新");
                apiinfoesService.insert(ApiinfoesHelper.setApiinfoes(apiinfoes, orderid, GsonUtil.createJsonString(netState)));
                return netState;
            }

            if (callbackinfoes != null) {
                String caller = callbackinfoes.getCaller().replace("+86", "").trim(); // 主叫
                String callee = callbackinfoes.getCalle164().replace("+86", "").trim(); // 被叫
                // a.若存在此话单进行更新
                if (hold_time == null || hold_time.isEmpty() || hold_time.equals("0")) {
                    // a.0时长直接更新话单
                    callbackinfoes.setSysnum("CP推送话单");
                    callbackinfoes.setCalltime(new Date(new Long(start_time + "000")));
                    callbackinfoes.setEndtime(new Date(new Long(end_time + "000")));
                    callbackinfoes.setFwdtime(Produce.getNowDate());
                    callbackinfoes.setMoney(new BigDecimal(0));
                    callbackinfoes.setOmoney(new BigDecimal(0));
                    callbackinfoes.setTimecount(0);
                    callbackinfoes.setStatus("未接通");
                    callbackinfoesService.updateByPrimaryKeySelective(callbackinfoes);
                    netState.setErrorCode(NetState.SUCCESS_CONN);
                    netState.setData("成功更新订单");
                    System.out.println("成功更新订单");
                } else {
                    // b.非0时长
                    float mins = Float.parseFloat(hold_time) / 60;
                    double secound = Math.ceil(mins);// 分钟数
                    // 查询该用户
                    SubscribersExample subscribersExample = new SubscribersExample();
                    subscribersExample.getOredCriteria()
                            .add(subscribersExample.createCriteria().andMobileEqualTo(caller)
                                    .andParentidEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                    List<Subscribers> subs = subscribersService.selectByExample(subscribersExample);
                    Subscribers user = null;
                    // 查询该代理
                    UsersExample usersExample = new UsersExample();
                    usersExample.getOredCriteria().add(usersExample.createCriteria()
                            .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                    List<Users> users = usersService.selectByExample(usersExample);
                    Users agent = null;
                    // VOS查询该账号
                    if ((subs != null && subs.size() == 1) && (users != null && users.size() == 1)) {
                        user = subs.get(0);
                        agent = users.get(0);

                        // 查询分享者 变更前话费余额
                        BigDecimal beforeB = new BigDecimal(0);
                        //备注
                        String remark = null;
                        try {
                            // TODO 暂时配注
                            String userR = VosHelper
                                    .GetVosAccount("{accounts:['" + agent.getAgentprefix() + user.getMobile() + "']}");
                            if (userR != null) {
                                VosModelList userR1 = GsonUtil.getObject(userR, VosModelList.class);
                                if (userR1.retCode == 0) {
                                    beforeB = userR1.infoCustomers[0].getMoney();
                                } else {
                                    beforeB = new BigDecimal(0);
                                    remark = "暂无记录";
                                }
                            }
                        } catch (Exception e) {
                            beforeB = new BigDecimal(0);
                            remark = "暂无记录";
                        }
                        // 变更话费金额
                        BigDecimal changeB = new BigDecimal(0);

                        // TODO 查询费率
                        // String results = VosHelper
                        // .GetVosAccount("{accounts:['" +
                        // agent.getAgentprefix() + user.getMobile() + "']}");
                        // VosModelList v1 = GsonUtil.getObject(results,
                        // VosModelList.class);
                        // String fe = v1.infoCustomers[0].feeRateGroup;
                        // System.out.println(fe);
                        Freeroutes f = null;
                        String freeroute = agent.getFreeroute();
                        // TODO 费率组检测
                        if (freeroute.contains("随便打") || freeroute.contains("季卡") || freeroute.contains("月卡") || freeroute.contains("0.25")) {
                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.25), true, 60,
                                    Produce.getNowDate());
                        } else if (freeroute.contains("0.2") || freeroute.contains("年卡")) {
                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.2), true, 60,
                                    Produce.getNowDate());
                        } else if (freeroute.contains("0.3")) {
                            f = new Freeroutes(Produce.getUUID(), "随便打", new BigDecimal(0.3), true, 60,
                                    Produce.getNowDate());
                        } else if (freeroute.contains("高频") || freeroute.contains("乐淘通") || freeroute.contains("0.6")) {
                            f = new Freeroutes(Produce.getUUID(), "高频用户", new BigDecimal(0.6), true, 60,
                                    Produce.getNowDate());
                        } else {
                            FreeroutesExample freeroutesExample = new FreeroutesExample();
                            freeroutesExample.getOredCriteria().add(freeroutesExample.createCriteria()
                                    .andNameLike("%" + freeroute + "%").andDatastatusEqualTo(true));
                            List<Freeroutes> freeroutes = freeroutesService.selectByExample(freeroutesExample);
                            if (freeroutes != null && freeroutes.size() > 0) {
                                f = freeroutes.get(0);
                            }
                        }

                        if (f != null) {
                            if (f.getRatelength() != 60) {
                                float min = Float.parseFloat(hold_time) / f.getRatelength();
                                secound = Math.ceil(min);// 分钟数
                            }
                            // 计算费用
                            BigDecimal money = f.getFeelroute().multiply(new BigDecimal(secound)); // 费用
                            changeB = money;
                            BigDecimal fl = JHHelper.JH;
                            BigDecimal omon = fl.multiply(new BigDecimal(secound));
                            System.out.println("secound:" + secound + "money:" + money + "omon:" + omon);
                            // 进行扣费
                            if (user.getType() == 7) {
                                UsersExample listsExample = new UsersExample();
                                listsExample.getOredCriteria().add(listsExample.createCriteria()
                                        .andIdEqualTo(user.getShopid()).andDatastatusEqualTo(true));
                                List<Users> lists = usersService.selectByExample(listsExample);
                                Users list = null;
                                UsersExample agents1sExample = new UsersExample();
                                agents1sExample.getOredCriteria().add(agents1sExample.createCriteria()
                                        .andIdEqualTo(callbackinfoes.getParentid()).andDatastatusEqualTo(true));
                                List<Users> agents1s = usersService.selectByExample(agents1sExample);
                                Users agents1 = null;
                                if ((lists != null && lists.size() == 1)
                                        || (agents1s != null && agents1s.size() == 1)) {
                                    list = lists.get(0);
                                    agents1 = agents1s.get(0);
                                    VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getAgentprefix()
                                            + callbackinfoes.getCaller() + "\",\"ownerType\":\"2\",\"money\":\"-"
                                            + money + "\",\"memo\":\"用户通话扣费:" + money + "元\"}");
                                    VosHelper.PayVosAccount("{\"ownerName\":\"" + list.getUsername()
                                            + "\",\"ownerType\":\"2\",\"money\":\"-" + money + "\",\"memo\":\"用户通话扣费:"
                                            + money + "元\"}");
                                    VosHelper.PayVosAccount("{\"ownerName\":\"" + agents1.getUsername()
                                            + "j\",\"ownerType\":\"2\",\"money\":\"-" + omon + "\",\"memo\":\"用户通话扣线路费:"
                                            + omon + "元\"}");
                                }
                                callbackinfoes.setMoney(money);
                            } else {
                                callbackinfoes.setMoney(new BigDecimal(0));
                            }
                            // 更新话单
                            callbackinfoes.setSysnum("CP推送话单");
                            callbackinfoes.setCalltime(new Date(new Long(start_time + "000")));
                            callbackinfoes.setEndtime(new Date(new Long(end_time + "000")));
                            callbackinfoes.setFwdtime(new Date(new Long(start_time + "000")));
                            callbackinfoes.setOmoney(omon);
                            callbackinfoes.setTimecount(Integer.parseInt(hold_time));
                            callbackinfoes.setStatus("接通");
                            callbackinfoesService.updateByPrimaryKeySelective(callbackinfoes);

//                            if (agent.getId().equals("875ebeb6fe52464ca8c9c418199e774b")){
//                                WebHelper.PostData(" http://laofengge.ruiqinet.com/laofengge/login/test", "param=" + JSONObject.fromObject(callbackinfoes), null, null);
//                            }

                            try {
                                // 话费变更记录
                                changeRecordService.insertSelective(new ChangeRecord(user.getParentid(), user.getShopid(), user.getId(),
                                        Produce.getNowDate(), beforeB, changeB, 0, user.getEndtime(), user.getEndtime(), "拨打电话",
                                        BigDecimal.valueOf(user.getShopBalance()), BigDecimal.valueOf(0), 0,
                                        new SimpleDateFormat("yyyy-MM-dd").parse(user.getShopEnddate()),
                                        new SimpleDateFormat("yyyy-MM-dd").parse(user.getShopEnddate()), "拨打电话", remark));
                            } catch (Exception e) {
                                logsService.insert(CommContent.TYPE_CREATE, user.getMobile() + "拨打电话余额变更记录异常", agent.getUsername(), true,
                                        IP.getIpAddr(request));
                            }

                            netState.setErrorCode(NetState.SUCCESS_CONN);
                            netState.setData("成功更新订单");
                            System.out.println("成功更新订单");
                        } else {
                            netState.setErrorCode(NetState.NODATA);
                            netState.setData("无法匹配此费率");
                            System.out.println("无法匹配此费率");
                        }
                    } else {
                        netState.setErrorCode(NetState.NODATA);
                        netState.setData("用户或者代理不存在");
                        System.out.println("用户或者代理不存在");
                    }
                }
            } else {
                netState.setErrorCode(NetState.NODATA);
                netState.setData("话单不存在");
                System.out.println("话单不存在");
            }
        } else {
            netState.setErrorCode(NetState.SYSTEM_ERROR);
            netState.setData("话单返回值解析失败");
            System.out.println("话单返回值解析失败");
        }

//        response.getWriter().print("1");
        response.getOutputStream().print("1");
        apiinfoesService.insert(ApiinfoesHelper.setApiinfoes(apiinfoes, orderid, GsonUtil.createJsonString(netState)));
        return netState;
    }

    // 维信端 通话记录
    @RequestMapping(value = "/wxCallLog", method = RequestMethod.POST)
    public @ResponseBody
    NetState wxCallLog(HttpServletRequest request, String Caller, String ParentID) {
        NetState netState = new NetState();

        if (Caller == null || Caller.equals("")) {
            netState.setErrorCode(NetState.SYSTEM_ERROR);
            netState.setData("系统未接受到手机号码，请重新登陆试试");
        }
        if (ParentID == null || ParentID.equals("")) {
            netState.setErrorCode(NetState.SYSTEM_ERROR);
            netState.setData("系统丢失了您的登陆信息，请重新登陆试试");
        }

        // 随便打的维信号 页面
        // String pid = "58162318-deca-4442-8e38-743b7729aa5b";
        // 查询通话记录
        List<Callbackinfoes> callbackinfoes = callbackinfoesService.selectByCallerAndParentID(Caller, ParentID);

        if (callbackinfoes != null && callbackinfoes.size() > 0) {

            for (Callbackinfoes c : callbackinfoes) {
                c.setCalluptime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(c.getCalltime()));
            }

            netState.setErrorCode(NetState.SUCCESS_CONN);
            netState.setData("查询成功");
            netState.setJson(callbackinfoes);
        } else {
            netState.setErrorCode(NetState.NODATA);
            netState.setData("查询成功，未查询到通话记录");
            netState.setJson(null);
        }

//        Apiinfoes apiinfoes = ApiinfoesHelper.createApiinfoes(request, " 通话记录");
//        apiinfoesService.insert(ApiinfoesHelper.setApiinfoes(apiinfoes, Produce.parmsToString(Caller, ParentID),
//                GsonUtil.createJsonString(netState)));
        return netState;
    }

    // 维信端 通话记录
    @RequestMapping(value = "/callEndPic", method = RequestMethod.POST)
    public @ResponseBody
    NetState callEndPic(HttpServletRequest request, String userId, Adversiments adversiments) {
        NetState netState = new NetState();

        if (adversiments.getParentid() == null || adversiments.getParentid().equals("")) {
            netState.setErrorCode(NetState.SYSTEM_ERROR);
            netState.setData("参数异常");
        }

        List<Adversiments> adversimentsList = null;
        if (userId != null && !userId.equals("")) {
            Subscribers subscribers = subscribersService.selectByPrimaryKey(userId);
            adversiments.setParentid(subscribers.getShopid());
            adversimentsList = adversimentsService.selectByAll(adversiments);
            if (adversimentsList == null) {
                adversiments.setParentid(subscribers.getParentid());
                adversimentsList = adversimentsService.selectByAll(adversiments);
            }
        } else {
            adversimentsList = adversimentsService.selectByAll(adversiments);
        }

        if (adversimentsList != null && adversimentsList.size() > 0) {
            netState.setErrorCode(NetState.SUCCESS_CONN);
            netState.setData("查询成功");
            netState.setJson(adversimentsList);
        } else {
            netState.setErrorCode(NetState.NODATA);
            netState.setData("查询成功，未查询到图片");
            netState.setJson(null);
        }

        return netState;
    }
}
